{"record":{"id":"8ed05dfc5b9ca238","repo":"hcengineering/platform","slug":"unexpected-exception-could-not-detect-node-path","errorCode":null,"errorMessage":"Unexpected exception: could not detect node path","messagePattern":"Unexpected exception: could not detect node path","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/communication/common/scripts/install-run.js","lineNumber":746,"sourceCode":"    }\n    else {\n        throw result.error || new Error('An unknown error occurred.');\n    }\n}\nfunction runWithErrorAndStatusCode(logger, fn) {\n    process.exitCode = 1;\n    try {\n        const exitCode = fn();\n        process.exitCode = exitCode;\n    }\n    catch (e) {\n        logger.error('\\n\\n' + e.toString() + '\\n\\n');\n    }\n}\nfunction _run() {\n    const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, rawPackageSpecifier /* qrcode@^1.2.0 */, packageBinName /* qrcode */, ...packageBinArgs /* [-f, myproject/lib] */] = process.argv;\n    if (!nodePath) {\n        throw new Error('Unexpected exception: could not detect node path');\n    }\n    if (path__WEBPACK_IMPORTED_MODULE_3__.basename(scriptPath).toLowerCase() !== 'install-run.js') {\n        // If install-run.js wasn't directly invoked, don't execute the rest of this function. Return control\n        // to the script that (presumably) imported this file\n        return;\n    }\n    if (process.argv.length < 4) {\n        console.log('Usage: install-run.js <package>@<version> <command> [args...]');\n        console.log('Example: install-run.js qrcode@1.2.2 qrcode https://rushjs.io');\n        process.exit(1);\n    }\n    const logger = { info: console.log, error: console.error };\n    runWithErrorAndStatusCode(logger, () => {\n        const rushJsonFolder = findRushJsonFolder();\n        const rushCommonFolder = _ensureAndJoinPath(rushJsonFolder, 'common');\n        const packageSpecifier = _parsePackageSpecifier(rawPackageSpecifier);\n        const name = packageSpecifier.name;\n        const version = _resolvePackageVersion(logger, rushCommonFolder, packageSpecifier);","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/communication/common/scripts/install-run.js#L728-L764","documentation":"install-run.js's `_run()` destructures process.argv expecting argv[0] to be the node executable path and argv[1] to be the script path. If argv[0] (nodePath) is missing/falsy, it throws this Error — it indicates a broken invocation environment rather than a user error in the package spec.","triggerScenarios":"Executing the script in an environment where process.argv[0] is empty or stripped: embedding the script as a REPL/module evaluation (node -e, node --eval), unusual embedders/forks of Node that set argv[0] to empty, or launching via a tool that rewrites argv.","commonSituations":"Running install-run.js via node -e 'require(...)' or programmatic imports instead of as a CLI script; custom embedded Node runtimes; patched launchers that pass empty argv[0]. Note the script also early-returns if the basename isn't install-run.js, so direct imports normally don't reach this throw.","solutions":["Run the script normally as a CLI: `node common/scripts/install-run.js ...` so argv[0] is the node binary.","Don't import/install-run as a module from node -e or REPL contexts; if you need the logic programmatically, call installAndRun directly instead of _run.","Check the launcher (shell wrapper, pm2, node fork with execArgv) isn't clearing process.argv[0].","Verify you're using a standard Node build; try the official node binary to rule out an embedded runtime."],"exampleFix":"// before\nnode -e \"require('./common/scripts/install-run.js')\" qrcode@1.4.2 qrcode\n// Error: Unexpected exception: could not detect node path\n// after\nnode ./common/scripts/install-run.js qrcode@1.4.2 qrcode","handlingStrategy":"validation","validationCode":"if (!process.argv[0] || !process.argv[0].endsWith('node')) {\n  throw new Error('Run install-run.js via the node CLI, not via -e/REPL/embedded runtime')\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runBootstrap()\n} catch (e) {\n  if (String(e).includes('could not detect node path')) {\n    console.error('Invoke as: node common/scripts/install-run.js <pkg> <bin> [args]')\n  }\n  throw e\n}","preventionTips":["Always execute install-run.js as a CLI script with node, never via node -e or import in REPL.","Avoid launchers that rewrite or empty process.argv[0].","Use official Node builds rather than embedded/custom runtimes for rush bootstraps.","Document the correct invocation in repo scripts/package.json."],"tags":["node","argv","rush","cli","bootstrap"],"backgroundTag":"missing-node-executable","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}