hcengineering/platform · error · Error
The NPM executable does not exist
Error message
The NPM executable does not exist
What it means
After resolving _npmPath, getNpmPath trims it and checks fs.existsSync. If the resolved path does not exist on disk it throws this error. This means a path was returned (registry or `command -v`) but the file there is missing or stale.
Source
Thrown at foundations/communication/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
- Reinstall Node.js/npm so an executable actually exists at the resolved path.
- Remove stale shims/symlinks (e.g. `which -a npm`, fix ~/.nvm/alias or /usr/local/bin/npm).
- Reload the shell/CI environment after installing or upgrading Node (refresh PATH).
- Check the path printed by `command -v npm` and verify it exists with `ls -la`.
Example fix
// before: stale nvm shim ls -l $(command -v npm) # dangling symlink to ~/.nvm/versions/node/v18.0.0 // after nvm install 20 && nvm alias default 20 && hash -r
Defensive patterns
Strategy: validation
Validate before calling
const { execSync } = require('child_process');
const p = execSync('command -v npm').toString().trim();
const fs = require('fs');
if (!fs.existsSync(p)) throw new Error(`npm path resolved to missing file: ${p}; reinstall Node.js`); Try / catch
try { runInstall(); } catch (e) { if (/NPM executable does not exist/.test(e.message)) { console.error('Stale npm path; reinstall Node and reload PATH'); process.exit(1); } throw e; } Prevention
- Run `hash -r` after switching node versions
- Clean up stale nvm shims and version directories
- Recreate CI runners after major Node upgrades
When it happens
Trigger: `command -v npm` or the Windows registry yields a path that no longer points to an existing executable — e.g. npm uninstalled/upgraded after PATH or registry cache recorded it, or a broken symlink in the node bin directory.
Common situations: Switching nvm versions so old shims point at removed node installs; partially completed Node upgrades; Windows registry entries left by an uninstalled Node; stale shims in /usr/local/bin.
Related errors
- Unable to determine the path to the NPM tool: ${e}
- Unable to create package.json: ${e}
- Unable to determine the path to the NPM tool: ${e}
- The NPM executable does not exist
- Error syncing .npmrc file: ${e}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/68436544faf39cd3.
Report an issue: GitHub.