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: on Windows it queries the registry/path, elsewhere it runs `command -v npm`. If either shell/registry lookup fails, it wraps the caught exception in this error. It indicates the script cannot find npm on the machine running the install-and-run script.

Source

Thrown at foundations/communication/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 in the environment or use an image that includes it (e.g. node:20).
  2. Ensure npm is on PATH for non-interactive shells (add nvm/node bin dir to PATH before running).
  3. Verify with `command -v npm` in the same shell the script runs under.
  4. If npm is deliberately absent, run the target command directly instead of via install-run.js.

Example fix

// before (Dockerfile)
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y git
// after
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y git curl
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs
Defensive patterns

Strategy: validation

Validate before calling

const which = require('child_process').spawnSync('command -v npm', { shell: true, stdio: [] });
if (which.status !== 0) throw new Error('npm is not on PATH; install Node.js before running install-run');

Try / catch

try { runInstall(); } catch (e) { if (/Unable to determine the path to the NPM tool/.test(e.message)) { console.error('Install Node.js/npm or fix PATH; cause:', e.message); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: Running the script on a machine where `command -v npm` returns nonzero (npm not installed, not on PATH) or the Windows registry lookup throws; the underlying exception is embedded in the message.

Common situations: Minimal CI Docker images without Node/npm preinstalled; npm installed via a non-PATH manager (nvm) inside a non-interactive shell; PATH stripped in cron or CI runners.

Related errors


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