hcengineering/platform · error · 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, using `where npm` on Windows or `command -v npm` on *NIX/Darwin via execSync. If that lookup fails for any reason, the catch block rethrows it wrapped in this error.

Source

Thrown at foundations/core/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 Node.js/npm or add its bin directory to PATH and re-run
  2. In CI, use a node setup step (e.g. actions/setup-node) before running rush scripts
  3. Check the wrapped cause `e` for the underlying execSync failure
  4. For nvm users, ensure the script is run from a shell where nvm/node are on PATH

Example fix

// before (Dockerfile)
FROM node:20-slim
RUN apt-get update
// after (ensure npm present & on PATH)
FROM node:20
# or: RUN corepack/npm available at /usr/local/bin/npm
Defensive patterns

Strategy: try-catch

Validate before calling

try { child_process.execSync(process.platform === 'win32' ? 'where npm' : 'command -v npm', { stdio: [] }); } catch { throw new Error('npm is not on PATH; install Node.js or fix PATH'); }

Try / catch

try { const npm = getNpmPath(); }
catch (e) { if (/Unable to determine the path to the NPM tool/.test(e.message)) { console.error('Install Node.js/npm or fix PATH before running rush scripts'); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: npm is not installed or not on PATH, so `command -v npm` / `where npm` returns non-zero or fails to spawn; execSync throws and gets wrapped.

Common situations: Minimal CI containers without npm on PATH; nvm-managed node where the script runs under a shell without nvm loaded; corrupted PATH in cron/systemd contexts.

Related errors


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