{"record":{"id":"bd68ed88d72b5b5b","repo":"hcengineering/platform","slug":"the-npm-executable-does-not-exist-bd68ed","errorCode":null,"errorMessage":"The NPM executable does not exist","messagePattern":"The NPM executable does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"foundations/utils/common/scripts/install-run.js","lineNumber":395,"sourceCode":"            if (_isWindows()) {\n                // We're on Windows\n                const whereOutput = child_process__WEBPACK_IMPORTED_MODULE_0__.execSync('where npm', { stdio: [] }).toString();\n                const lines = whereOutput.split(os__WEBPACK_IMPORTED_MODULE_2__.EOL).filter((line) => !!line);\n                // take the last result, we are looking for a .cmd command\n                // see https://github.com/microsoft/rushstack/issues/759\n                _npmPath = lines[lines.length - 1];\n            }\n            else {\n                // We aren't on Windows - assume we're on *NIX or Darwin\n                _npmPath = child_process__WEBPACK_IMPORTED_MODULE_0__.execSync('command -v npm', { stdio: [] }).toString();\n            }\n        }\n        catch (e) {\n            throw new Error(`Unable to determine the path to the NPM tool: ${e}`);\n        }\n        _npmPath = _npmPath.trim();\n        if (!fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(_npmPath)) {\n            throw new Error('The NPM executable does not exist');\n        }\n    }\n    return _npmPath;\n}\nfunction _ensureFolder(folderPath) {\n    if (!fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(folderPath)) {\n        const parentDir = path__WEBPACK_IMPORTED_MODULE_3__.dirname(folderPath);\n        _ensureFolder(parentDir);\n        fs__WEBPACK_IMPORTED_MODULE_1__.mkdirSync(folderPath);\n    }\n}\n/**\n * Create missing directories under the specified base directory, and return the resolved directory.\n *\n * Does not support \".\" or \"..\" path segments.\n * Assumes the baseFolder exists.\n */\nfunction _ensureAndJoinPath(baseFolder, ...pathSegments) {","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/utils/common/scripts/install-run.js#L377-L413","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install Node.js/npm (or use a setup-node step) so the npm executable exists at the resolved path","Fix the PATH in the CI/job environment so `npm --version` resolves to a real executable","Verify manually: run `which npm` (or `where npm` on Windows) and confirm the file exists and runs","If using a version manager (nvm, volta), ensure it is initialized in non-interactive shells"],"exampleFix":"// before: CI job with no node\nsteps:\n  - script: ./common/scripts/install-run.js install-run -- pnpm install\n// after\nsteps:\n  - task: NodeTool@0\n    inputs:\n      versionSpec: '18.x'\n  - script: node ./common/scripts/install-run.js install-run -- pnpm install","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process');\nconst fs = require('fs');\nfunction assertNpmAvailable() {\n  const npmPath = process.platform === 'win32'\n    ? execSync('where npm', { encoding: 'utf8' }).split('\\r\\n')[0]\n    : execSync('which npm', { encoding: 'utf8' }).trim();\n  if (!npmPath || !fs.existsSync(npmPath)) {\n    throw new Error('npm is not installed or not on PATH; install Node.js first');\n  }\n}\nassertNpmAvailable();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a NodeTool/setup-node step before any script that shells out to npm","Assert `which npm` succeeds as a CI preflight check","Initialize version managers (nvm/volta) in non-interactive shells"],"tags":["npm","environment","path","missing-executable"],"backgroundTag":"npm-executable-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}