{"record":{"id":"f2e50e662e3f0466","repo":"hcengineering/platform","slug":"unable-to-determine-the-path-to-the-npm-tool-e-f2e50e","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/utils/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/utils/common/scripts/install-run.js#L373-L409","documentation":"getNpmPath locates the npm executable: on Windows via 'npm.cmd' lookup, elsewhere via `command -v npm`. If locating npm throws (npm not installed, not on PATH, execSync failure) the error is rethrown as 'Unable to determine the path to the NPM tool: <cause>'; a subsequent existsSync check separately throws 'The NPM executable does not exist'.","triggerScenarios":"Running install-run.js on a machine where npm is not installed or not on PATH, so `command -v npm` (or the Windows lookup) fails inside getNpmPath.","commonSituations":"Minimal Docker images with node but no npm; corrupted PATH in CI; using a node runtime installed without npm (e.g. some manual builds); nvm not initialized in the shell running the script.","solutions":["Install npm / Node.js (npm ships with the official Node installer)","Fix PATH so npm is reachable, e.g. source nvm.sh or export PATH=\"$(npm config --global prefix)/bin:$PATH\" in CI","Verify with `command -v npm` (or `where npm` on Windows) before running the script","Use an official node Docker image that includes npm"],"exampleFix":"// before (CI step)\n- run: node common/scripts/install-run.js ...\n// after\n- run: |\n    source ~/.nvm/nvm.sh\n    command -v npm   # sanity check\n    node common/scripts/install-run.js ...","handlingStrategy":"try-catch","validationCode":"const { execSync } = require('child_process')\nfunction assertNpmAvailable() {\n  try {\n    execSync(process.platform === 'win32' ? 'where npm' : 'command -v npm', { stdio: [] })\n  } catch {\n    throw new Error('npm is not installed or not on PATH; install Node.js or fix PATH before running')\n  }\n}","typeGuard":"null","tryCatchPattern":"try {\n  runInstallScript()\n} catch (e) {\n  if (String(e.message).startsWith('Unable to determine the path to the NPM tool:')) {\n    console.error('npm not found: install Node.js/npm or source nvm and fix PATH')\n    process.exit(1)\n  }\n  throw e\n}","preventionTips":["Use official node Docker images that bundle npm","In CI, source nvm/init shells before running install-run scripts","Add a preflight `command -v npm` step to pipelines that use install-run.js","Pin the Node toolchain so PATH assumptions stay valid across agents"],"tags":["npm","path","environment"],"backgroundTag":"executable-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}