{"record":{"id":"5f359863aa1f6733","repo":"hcengineering/platform","slug":"unexpected-exception-could-not-detect-node-path-5f3598","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/core/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/core/common/scripts/install-run.js#L728-L764","documentation":"_run is the CLI entry point of install-run.js; it destructures process.argv expecting argv[0] to be the node executable path. If nodePath is missing/empty — which should never happen in a normally spawned node process — it throws 'Unexpected exception: could not detect node path' to fail loudly on an unexpected runtime environment.","triggerScenarios":"Invoking the script in a way where process.argv[0] is falsy: embedding/evaluating the module in a nonstandard runtime, custom launchers that strip argv, or test harnesses that stub process.argv with an empty array before requiring the script.","commonSituations":"Bundling or importing install-run.js into another tool that executes _run with a manipulated argv; exotic embedded Node runtimes; misconfigured wrappers that call the script without the node binary in argv.","solutions":["Run the script normally: `node <path>/install-run.js <packageSpec> <bin> [args...]` so argv[0] is the node path.","If embedding the module, ensure process.argv[0] is set or gate _run so it isn't executed on import.","Check any wrapper/launcher code that rewrites or truncates process.argv before requiring the script.","Upgrade to a standard Node runtime (not a stripped embedded build) to execute the bootstrap script."],"exampleFix":"// before (test stub)\nprocess.argv = []; require('./install-run.js');\n// after\nprocess.argv = [process.execPath, 'install-run.js', 'qrcode@^1.2.0', 'qrcode']; require('./install-run.js');","handlingStrategy":"validation","validationCode":"// Before requiring/executing the bootstrap script, ensure argv looks like a normal node invocation:\nif (!process.argv[0] || !process.argv[1]) {\n  process.argv = [process.execPath, ...process.argv.filter(Boolean)];\n}","typeGuard":"function hasNodePathInArgv(argv) {\n  return Array.isArray(argv) && typeof argv[0] === 'string' && argv[0].length > 0;\n}","tryCatchPattern":"try {\n  require('./install-run.js'); // executes _run when invoked as a script\n} catch (e) {\n  if (/could not detect node path/.test(e.message)) {\n    console.error('process.argv[0] was empty; run the script via `node install-run.js ...` or set process.argv correctly.');\n  }\n  throw e;\n}","preventionTips":["Always launch the script with the node binary (`node install-run.js ...`), never via custom loaders that strip argv","Don't mutate process.argv in test harnesses before requiring bootstrap scripts","Avoid embedding install-run.js in bundles that execute _run on import","Use process.execPath when synthesizing argv programmatically"],"tags":["node","argv","cli","bootstrap"],"backgroundTag":"missing-node-path","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}