hcengineering/platform · error

The NPM executable does not exist

Error message

The NPM executable does not exist

What it means

After resolving the npm path (via env variable, execPath sibling, or `command -v npm`), the script verifies the path exists on disk with fs.existsSync. If not, it throws this standalone message — the location was 'determined' but points to a nonexistent binary.

Source

Thrown at foundations/server/common/scripts/install-run.js:395

            if (_isWindows()) {
                // We're on Windows
                const whereOutput = child_process__WEBPACK_IMPORTED_MODULE_0__.execSync('where npm', { stdio: [] }).toString();
                const lines = whereOutput.split(os__WEBPACK_IMPORTED_MODULE_2__.EOL).filter((line) => !!line);
                // take the last result, we are looking for a .cmd command
                // see https://github.com/microsoft/rushstack/issues/759
                _npmPath = lines[lines.length - 1];
            }
            else {
                // We aren't on Windows - assume we're on *NIX or Darwin
                _npmPath = child_process__WEBPACK_IMPORTED_MODULE_0__.execSync('command -v npm', { stdio: [] }).toString();
            }
        }
        catch (e) {
            throw new Error(`Unable to determine the path to the NPM tool: ${e}`);
        }
        _npmPath = _npmPath.trim();
        if (!fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(_npmPath)) {
            throw new Error('The NPM executable does not exist');
        }
    }
    return _npmPath;
}
function _ensureFolder(folderPath) {
    if (!fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(folderPath)) {
        const parentDir = path__WEBPACK_IMPORTED_MODULE_3__.dirname(folderPath);
        _ensureFolder(parentDir);
        fs__WEBPACK_IMPORTED_MODULE_1__.mkdirSync(folderPath);
    }
}
/**
 * Create missing directories under the specified base directory, and return the resolved directory.
 *
 * Does not support "." or ".." path segments.
 * Assumes the baseFolder exists.
 */
function _ensureAndJoinPath(baseFolder, ...pathSegments) {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the resolved path exists: run `command -v npm` then `ls` the result
  2. Unset stale npm_config_npm_path or update it to the current npm absolute path
  3. Reinstall Node.js so node/npm are consistent (which npm; which node)
  4. Switch nvm to the installed version (nvm use <version>) so PATH points to existing binaries

Example fix

// before
export npm_config_npm_path=/old/node versions/16.0.0/bin/npm
// after
unset npm_config_npm_path   # let the script auto-detect, or:
export npm_config_npm_path=$(command -v npm)
Defensive patterns

Strategy: validation

Validate before calling

const p = process.env.npm_config_npm_path || child_process.execSync('command -v npm').toString().trim();
if (!fs.existsSync(p)) throw new Error(`npm binary missing at ${p}; reinstall Node.js`);

Type guard

function npmBinaryExists() {
  try { const p = child_process.execSync('command -v npm', { stdio: [] }).toString().trim(); return p.length > 0 && fs.existsSync(p); } catch { return false; }
}

Try / catch

try {
  runRushInstall();
} catch (e) {
  if (String(e).includes('The NPM executable does not exist')) {
    console.error('npm path resolved but binary missing — reinstall Node or fix npm_config_npm_path');
  } else throw e;
}

Prevention

When it happens

Trigger: npm_config_npm_path env var set to a stale/invalid path; Windows sibling-of-node npm.cmd missing after a Node upgrade; `command -v npm` returning a shim or symlink whose target was deleted; PATH cache referencing an old nvm version directory that was removed.

Common situations: Upgrading/downgrading Node via nvm leaves env pointing at an old, deleted version dir; manually deleted npm folder; container image where node was reinstalled after env was baked in.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/b374dd815e908f17. Report an issue: GitHub.