hcengineering/platform · error
Unexpected exception: could not detect node path or script p
Error message
Unexpected exception: could not detect node path or script path
What it means
_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.
Source
Thrown at foundations/server/common/scripts/install-run-rush.js:165
}
function _getBin(scriptName) {
switch (scriptName.toLowerCase()) {
case 'install-run-rush-pnpm.js':
return 'rush-pnpm';
case 'install-run-rushx.js':
return 'rushx';
default:
return 'rush';
}
}
function _run() {
const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
// Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
// appropriate binary inside the rush package to run
const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);
const bin = _getBin(scriptName);
if (!nodePath || !scriptPath) {
throw new Error('Unexpected exception: could not detect node path or script path');
}
let commandFound = false;
let logger = { info: console.log, error: console.error };
for (const arg of packageBinArgs) {
if (arg === '-q' || arg === '--quiet') {
// The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
// any normal informational/diagnostic information printed during startup.
//
// To maintain the same user experience, the install-run* scripts pass along this
// flag but also use it to suppress any diagnostic information normally printed
// to stdout.
logger = {
info: () => { },
error: console.error
};
}
else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
// We either found something that looks like a command (i.e. - doesn't start with a "-"),View on GitHub (pinned to 63e28dc964)
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
Example fix
// before (custom runner)
process.argv = ['build', '--to', 'myapp'];
require('./common/scripts/install-run-rush.js');
// after
process.argv = [process.execPath, '/repo/common/scripts/install-run-rush.js', 'build', '--to', 'myapp'];
require('./common/scripts/install-run-rush.js'); Defensive patterns
Strategy: validation
Validate before calling
if (!process.argv[0] || !process.argv[1]) {
throw new Error('Invoke via: node common/scripts/install-run-rush.js <args>');
} Type guard
function hasValidArgv(argv) {
return Array.isArray(argv) && typeof argv[0] === 'string' && typeof argv[1] === 'string' && argv[0].length > 0 && argv[1].length > 0;
} Try / catch
try {
runRush();
} catch (e) {
if (String(e).includes('could not detect node path or script path')) {
console.error('Run this script directly with node; do not mutate process.argv');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected exception: could not detect node path
- Unexpected exception: could not detect node path
- Unexpected exception: could not detect node path or script p
- Unexpected exception: could not detect node path
- Error building local installation folder (${path__WEBPACK_IM
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/742648ed05bc2315.
Report an issue: GitHub.