{"record":{"id":"742648ed05bc2315","repo":"hcengineering/platform","slug":"unexpected-exception-could-not-detect-node-path-o-742648","errorCode":null,"errorMessage":"Unexpected exception: could not detect node path or script path","messagePattern":"Unexpected exception: could not detect node path or script path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/server/common/scripts/install-run-rush.js","lineNumber":165,"sourceCode":"}\nfunction _getBin(scriptName) {\n    switch (scriptName.toLowerCase()) {\n        case 'install-run-rush-pnpm.js':\n            return 'rush-pnpm';\n        case 'install-run-rushx.js':\n            return 'rushx';\n        default:\n            return 'rush';\n    }\n}\nfunction _run() {\n    const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;\n    // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the\n    // appropriate binary inside the rush package to run\n    const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);\n    const bin = _getBin(scriptName);\n    if (!nodePath || !scriptPath) {\n        throw new Error('Unexpected exception: could not detect node path or script path');\n    }\n    let commandFound = false;\n    let logger = { info: console.log, error: console.error };\n    for (const arg of packageBinArgs) {\n        if (arg === '-q' || arg === '--quiet') {\n            // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress\n            // any normal informational/diagnostic information printed during startup.\n            //\n            // To maintain the same user experience, the install-run* scripts pass along this\n            // flag but also use it to suppress any diagnostic information normally printed\n            // to stdout.\n            logger = {\n                info: () => { },\n                error: console.error\n            };\n        }\n        else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {\n            // We either found something that looks like a command (i.e. - doesn't start with a \"-\"),","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/server/common/scripts/install-run-rush.js#L147-L183","documentation":"_run destructures process.argv expecting argv[0] to be the node executable path and argv[1] to be this script's path. If either is missing (falsy), the script cannot know which node binary and rush bin to invoke, so it throws.","triggerScenarios":"Running the script in an environment where process.argv was truncated or replaced (embedded node, custom runner that filters argv); invoking the script through a wrapper that does not pass node as argv[0]; programmatic require() then calling _run with an artificial argv.","commonSituations":"Custom CI launchers that rewrite process.argv; executing the script with unusual runtimes (Bun, Deno shims) that set argv differently; sandboxed environments stripping argv entries.","solutions":["Run the script normally via node: node common/scripts/install-run-rush.js <args> so argv[0]/argv[1] are populated","Check any wrapper code that mutates process.argv before the script runs and restore the standard [nodePath, scriptPath] prefix","If embedding, pass the full argv array including the node executable path"],"exampleFix":"// before (custom runner)\nprocess.argv = ['build', '--to', 'myapp'];\nrequire('./common/scripts/install-run-rush.js');\n// after\nprocess.argv = [process.execPath, '/repo/common/scripts/install-run-rush.js', 'build', '--to', 'myapp'];\nrequire('./common/scripts/install-run-rush.js');","handlingStrategy":"validation","validationCode":"if (!process.argv[0] || !process.argv[1]) {\n  throw new Error('Invoke via: node common/scripts/install-run-rush.js <args>');\n}","typeGuard":"function hasValidArgv(argv) {\n  return Array.isArray(argv) && typeof argv[0] === 'string' && typeof argv[1] === 'string' && argv[0].length > 0 && argv[1].length > 0;\n}","tryCatchPattern":"try {\n  runRush();\n} catch (e) {\n  if (String(e).includes('could not detect node path or script path')) {\n    console.error('Run this script directly with node; do not mutate process.argv');\n  } else throw e;\n}","preventionTips":["Always invoke via `node <script> <args>`, never by wrapping/mutating process.argv","Verify wrapper runners preserve the standard argv [execPath, scriptPath] prefix","Test bootstrap scripts in CI with plain node before adopting alternative runtimes"],"tags":["node","argv","rush"],"backgroundTag":"missing-process-argv","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}