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' folder next to process.execPath on Windows, or `command -v npm` on *NIX/Darwin — and caches the result. If that detection throws (npm not installed, not on PATH, execSync failing), this Error is thrown with the underlying cause embedded.

Source

Thrown at foundations/net/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

  1. Install npm or use a Node distribution that bundles it (official node images include npm).
  2. Ensure npm is on PATH in the executing shell (e.g. source nvm.sh in CI before running the script).
  3. Verify with `command -v npm` in the same environment; if it fails there, fix PATH first.
  4. Read the wrapped cause (${e}) in the message — ENOENT/ETC typically points to PATH or a missing shell.

Example fix

// before (CI)
- run: node common/scripts/install-run-rush.js install  // npm not on PATH
// after
- run: |
    source ~/.nvm/nvm.sh
    node common/scripts/install-run-rush.js install
Defensive patterns

Strategy: validation

Validate before calling

const { status } = spawnSync('command', ['-v', 'npm'], { shell: true, stdio: 'ignore' })
if (status !== 0) throw new Error('npm is not on PATH; install Node with npm or fix PATH before bootstrap')

Try / catch

try {
  const npmPath = getNpmPath()
} catch (e) {
  console.error('npm detection failed:', e.message, '— ensure npm is installed and on PATH')
  process.exit(1)
}

Prevention

When it happens

Trigger: The install-run bootstrap needs npm and: on *NIX, `command -v npm` fails because npm is not on PATH or not installed; on Windows, the expected npm.cmd next to node.exe is absent; execSync throws for any reason (ENOENT, shell unavailable).

Common situations: Container/CI images with node but not npm (e.g. minimal node:slim variants, custom images); nvm not loaded in non-interactive shells so PATH lacks the npm dir; restricted environments where spawning a shell fails.

Related errors


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