{"record":{"id":"194dbeca6a21ce47","repo":"hcengineering/platform","slug":"unable-to-determine-the-path-to-the-npm-tool-e-194dbe","errorCode":null,"errorMessage":"Unable to determine the path to the NPM tool: ${e}","messagePattern":"Unable to determine the path to the NPM tool: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/common/scripts/install-run.js","lineNumber":391,"sourceCode":" */\nfunction getNpmPath() {\n    if (!_npmPath) {\n        try {\n            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 *","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/net/common/scripts/install-run.js#L373-L409","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Install npm or use a Node distribution that bundles it (official node images include npm).","Ensure npm is on PATH in the executing shell (e.g. source nvm.sh in CI before running the script).","Verify with `command -v npm` in the same environment; if it fails there, fix PATH first.","Read the wrapped cause (${e}) in the message — ENOENT/ETC typically points to PATH or a missing shell."],"exampleFix":"// before (CI)\n- run: node common/scripts/install-run-rush.js install  // npm not on PATH\n// after\n- run: |\n    source ~/.nvm/nvm.sh\n    node common/scripts/install-run-rush.js install","handlingStrategy":"validation","validationCode":"const { status } = spawnSync('command', ['-v', 'npm'], { shell: true, stdio: 'ignore' })\nif (status !== 0) throw new Error('npm is not on PATH; install Node with npm or fix PATH before bootstrap')","typeGuard":null,"tryCatchPattern":"try {\n  const npmPath = getNpmPath()\n} catch (e) {\n  console.error('npm detection failed:', e.message, '— ensure npm is installed and on PATH')\n  process.exit(1)\n}","preventionTips":["Use official Node images/distributions that bundle npm; avoid stripped node builds.","In CI, source nvm/nvs initialization before running bootstrap scripts.","Add a preflight CI step: `command -v npm || (echo 'npm missing' && exit 1)`.","Keep node and npm from the same installation; don't mix global npm with relocated node."],"tags":["npm","path","environment"],"backgroundTag":"npm-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}