{"record":{"id":"2952ddab4d262195","repo":"hcengineering/platform","slug":"unable-to-determine-the-path-to-the-npm-tool-e-2952dd","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":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/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/core/common/scripts/install-run.js#L373-L409","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install Node.js/npm or add its bin directory to PATH and re-run","In CI, use a node setup step (e.g. actions/setup-node) before running rush scripts","Check the wrapped cause `e` for the underlying execSync failure","For nvm users, ensure the script is run from a shell where nvm/node are on PATH"],"exampleFix":"// before (Dockerfile)\nFROM node:20-slim\nRUN apt-get update\n// after (ensure npm present & on PATH)\nFROM node:20\n# or: RUN corepack/npm available at /usr/local/bin/npm","handlingStrategy":"try-catch","validationCode":"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'); }","typeGuard":null,"tryCatchPattern":"try { const npm = getNpmPath(); }\ncatch (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; }","preventionTips":["Use setup-node / nvm in CI and shells so npm is on PATH","Verify `npm -v` works in the same environment that runs rush scripts","For cron/systemd, set PATH explicitly to include the node bin dir"],"tags":["npm","path-lookup","environment"],"backgroundTag":"npm-not-found-on-path","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}