{"record":{"id":"25d6c77922ff1ef9","repo":"hcengineering/platform","slug":"unexpected-exception-could-not-detect-node-path-25d6c7","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/net/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/net/common/scripts/install-run.js#L728-L764","documentation":"_run() destructures process.argv expecting argv[0] to be the node executable path. If it is missing or empty — which should never happen under a normal node launch — the script throws, indicating the process was started in a way that corrupted argv.","triggerScenarios":"Invoking the script through an unusual launcher that strips or replaces process.argv[0], embedding the script in a runtime where argv is manually constructed and nodePath is undefined, or calling _run()/module top-level code from a non-CLI context.","commonSituations":"Custom Electron/embedded-node launches with hand-built argv arrays; wrappers that do `process.argv = [...]` before importing the script; exotic sandboxes that launch scripts without a node binary path.","solutions":["Launch the script normally: `node common/scripts/install-run.js <pkg>@<ver> <bin> [args]` so argv[0] is the node path.","If wrapping the script, keep process.argv[0] set to the node executable path.","Audit code that mutates process.argv before the script runs.","Check that the entrypoint wrapper (e.g. install-run-rush.js) is being executed by node, not sourced or embedded incorrectly."],"exampleFix":"// before: wrapper clobbers argv\nprocess.argv = [scriptPath, ...args];\nrequire('./install-run');\n// after: keep node path as argv[0]\nprocess.argv = [process.execPath, scriptPath, ...args];\nrequire('./install-run');","handlingStrategy":"validation","validationCode":"if (!process.argv[0] || !process.argv[0].endsWith('node')) {\n  throw new Error('Script must be launched via `node <script>` so argv[0] is the node path');\n}\n// run only after this check\nrunScript(process.argv.slice(2));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always invoke install-run scripts with `node script.js ...`.","Do not mutate process.argv in wrapper code before importing the script.","Keep process.execPath in argv[0] if you must rebuild argv programmatically."],"tags":["node","cli","argv","rush"],"backgroundTag":"missing-node-path","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}