{"record":{"id":"22da67c9c5865910","repo":"hcengineering/platform","slug":"unexpected-exception-could-not-detect-node-path-22da67","errorCode":null,"errorMessage":"Unexpected exception: could not detect node path","messagePattern":"Unexpected exception: could not detect node path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/server/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/server/common/scripts/install-run.js#L728-L764","documentation":"The _run entry point destructures process.argv expecting argv[0] to be the node executable path. In a normal Node process this is always present; if it is somehow missing, the script throws 'Unexpected exception: could not detect node path'. It is a defensive sanity check, so hitting it indicates a very unusual execution environment.","triggerScenarios":"Embedding or importing the script in a context where process.argv is empty or was replaced (custom runtimes, workers, bundled environments that strip argv); invoking Node in a way that omits argv[0].","commonSituations":"Embedding install-run.js inside another tool that fakes process.argv; exotic embedded JS runtimes; test harnesses that stub process.argv with an empty array.","solutions":["Run the script normally via node so process.argv[0] exists (node install-run.js <pkg> <version> <bin> [args...])","Do not stub or clear process.argv before importing/invoking the module","If embedding, pass a synthetic argv with the node path as the first element"],"exampleFix":"// before (test stub)\nprocess.argv = []\nawait import('./install-run.js')\n// after\nprocess.argv = [process.execPath, 'install-run.js', 'qrcode', '^1.2.0', 'qrcode']","handlingStrategy":"validation","validationCode":"if (!process.argv[0]) throw new Error('process.argv[0] (node path) missing; run via node')","typeGuard":"function hasNodePath(argv: string[]): argv is [string, ...string[]] {\n  return argv.length > 0 && !!argv[0]\n}","tryCatchPattern":null,"preventionTips":["Invoke the script via `node install-run.js ...` normally","Never stub/clear process.argv before importing the module","If embedding, synthesize argv with the node path as element 0"],"tags":["rush","process-argv","environment","bootstrap"],"backgroundTag":"missing-process-argv","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}