hcengineering/platform · critical

The NPM executable does not exist

Error message

The NPM executable does not exist

What it means

getNpmPath caches the resolved path to the npm executable (via `npm --version` shell lookup) and verifies it with fs.existsSync before returning. If the resolved path does not exist on disk, it throws 'The NPM executable does not exist'. This means npm could not be located in a usable form on this machine, so install-run.js cannot proceed to install or run packages.

Source

Thrown at foundations/utils/common/scripts/install-run.js:395

            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.
 *
 * Does not support "." or ".." path segments.
 * Assumes the baseFolder exists.
 */
function _ensureAndJoinPath(baseFolder, ...pathSegments) {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Install Node.js/npm (or use a setup-node step) so the npm executable exists at the resolved path
  2. Fix the PATH in the CI/job environment so `npm --version` resolves to a real executable
  3. Verify manually: run `which npm` (or `where npm` on Windows) and confirm the file exists and runs
  4. If using a version manager (nvm, volta), ensure it is initialized in non-interactive shells

Example fix

// before: CI job with no node
steps:
  - script: ./common/scripts/install-run.js install-run -- pnpm install
// after
steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '18.x'
  - script: node ./common/scripts/install-run.js install-run -- pnpm install
Defensive patterns

Strategy: validation

Validate before calling

const { execSync } = require('child_process');
const fs = require('fs');
function assertNpmAvailable() {
  const npmPath = process.platform === 'win32'
    ? execSync('where npm', { encoding: 'utf8' }).split('\r\n')[0]
    : execSync('which npm', { encoding: 'utf8' }).trim();
  if (!npmPath || !fs.existsSync(npmPath)) {
    throw new Error('npm is not installed or not on PATH; install Node.js first');
  }
}
assertNpmAvailable();

Prevention

When it happens

Trigger: Calling any exported entry of install-run.js (e.g. installAndRun, run) on a machine where the command used to locate npm (e.g. `npm --version` via spawnSync) resolves to a path that fails existsSync, or npm is not installed and the cached _npmPath is empty/invalid.

Common situations: CI container images without Node/npm installed; PATH misconfigured in the CI job so `npm` resolves to a broken shim; npm removed or upgraded and the shim at the resolved path deleted; Windows environments where the .cmd shim was moved.

Related errors


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