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: on Windows via 'npm.cmd' lookup, elsewhere via `command -v npm`. If locating npm throws (npm not installed, not on PATH, execSync failure) the error is rethrown as 'Unable to determine the path to the NPM tool: <cause>'; a subsequent existsSync check separately throws 'The NPM executable does not exist'.
Source
Thrown at foundations/utils/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
- Install npm / Node.js (npm ships with the official Node installer)
- Fix PATH so npm is reachable, e.g. source nvm.sh or export PATH="$(npm config --global prefix)/bin:$PATH" in CI
- Verify with `command -v npm` (or `where npm` on Windows) before running the script
- Use an official node Docker image that includes npm
Example fix
// before (CI step)
- run: node common/scripts/install-run.js ...
// after
- run: |
source ~/.nvm/nvm.sh
command -v npm # sanity check
node common/scripts/install-run.js ... Defensive patterns
Strategy: try-catch
Validate before calling
const { execSync } = require('child_process')
function assertNpmAvailable() {
try {
execSync(process.platform === 'win32' ? 'where npm' : 'command -v npm', { stdio: [] })
} catch {
throw new Error('npm is not installed or not on PATH; install Node.js or fix PATH before running')
}
} Type guard
null
Try / catch
try {
runInstallScript()
} catch (e) {
if (String(e.message).startsWith('Unable to determine the path to the NPM tool:')) {
console.error('npm not found: install Node.js/npm or source nvm and fix PATH')
process.exit(1)
}
throw e
} Prevention
- Use official node Docker images that bundle npm
- In CI, source nvm/init shells before running install-run scripts
- Add a preflight `command -v npm` step to pipelines that use install-run.js
- Pin the Node toolchain so PATH assumptions stay valid across agents
When it happens
Trigger: Running install-run.js on a machine where npm is not installed or not on PATH, so `command -v npm` (or the Windows lookup) fails inside getNpmPath.
Common situations: Minimal Docker images with node but no npm; corrupted PATH in CI; using a node runtime installed without npm (e.g. some manual builds); nvm not initialized in the shell running the script.
Related errors
- Unable to determine the path to the NPM tool: ${e}
- 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
- The NPM executable does not exist
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/f2e50e662e3f0466.
Report an issue: GitHub.