hcengineering/platform · error
Unable to determine the path to the NPM tool: ${e}
Error message
Unable to determine the path to the NPM tool: ${e} What it means
getNpmPath locates the npm executable, via the npm_config_npm_path env variable, path.join(process.execPath, '../npm') on Windows, or `command -v npm` on *NIX. If any of these detection steps throws, the error is wrapped as this message including the original cause.
Source
Thrown at foundations/server/common/scripts/install-run.js:391
*/
function getNpmPath() {
if (!_npmPath) {
try {
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.
*View on GitHub (pinned to 63e28dc964)
Solutions
- Ensure npm is installed and on PATH (node installers include it; reinstall Node.js if missing)
- Check PATH in the failing environment: `command -v npm` should succeed in the same shell/CI step
- If using nvm/fnm, load the version manager in the shell profile or CI step before running Rush scripts
- Set npm_config_npm_path to an absolute npm path as an override
Example fix
// before (CI step)
- run: node common/scripts/install-run-rush.js install
// after
- run: |
export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR/nvm.sh" && nvm use
node common/scripts/install-run-rush.js install Defensive patterns
Strategy: fallback
Validate before calling
try { child_process.execSync('command -v npm', { stdio: [] }); } catch { throw new Error('npm is not on PATH; install Node.js with npm'); } Type guard
function npmAvailable() {
try { return fs.existsSync(child_process.execSync('command -v npm', { stdio: [] }).toString().trim()); } catch { return false; }
} Try / catch
try {
runRushInstall();
} catch (e) {
if (String(e).includes('Unable to determine the path to the NPM tool')) {
console.error('Install Node.js/npm or load nvm before running Rush scripts');
process.exit(1);
} else throw e;
} Prevention
- Load nvm/fnm in shell profiles and CI steps before running Rush scripts
- Use official Node images in CI that include npm
- Smoke-test `npm --version` as a CI preflight step
- Set npm_config_npm_path explicitly in constrained environments
When it happens
Trigger: `command -v npm` fails because npm is not on PATH; spawn/execSync fails in restricted environments; on Windows the path derived from process.execPath contains no npm; env variable points to a nonexistent file.
Common situations: Minimal Docker images with node but no npm on PATH; broken nvm/fnm installation where node exists but npm shim is missing; CI containers running as different user without PATH set up; corrupted node installation.
Related errors
- Unable to determine the path to the NPM tool: ${e}
- Unable to determine the path to the NPM tool: ${e}
- The NPM executable does not exist
- Unable to determine the path to the NPM tool: ${e}
- The NPM executable does not exist
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/9debf8577d4ed829.
Report an issue: GitHub.