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

The _run bootstrap in install-run-rush.js destructures process.argv expecting [nodePath, scriptPath, ...args]. If node or the script path is missing from argv (which should never happen under normal node execution), it throws this error because it cannot determine which rush binary to run.

Source

Thrown at foundations/net/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

  1. Invoke the script normally: node common/scripts/install-run-rush.js <rush-args> so argv includes node path and script path.
  2. If spawning programmatically, ensure the argv array is [nodeExe, scriptPath, ...args] and not empty.
  3. Check for wrappers/patches that modify process.argv before this script runs and restore the defaults.
  4. Call rush install/build directly (globally installed rush) to bypass the bootstrap script.

Example fix

// before
spawnSync('node', [], { shell: true }) // argv empty -> error
// after
spawnSync(process.execPath, [path.join(__dirname, 'install-run-rush.js'), 'build'], { stdio: 'inherit' })
Defensive patterns

Strategy: validation

Validate before calling

if (process.argv.length < 2 || !process.argv[1].endsWith('install-run-rush.js')) {
  throw new Error('Script must be invoked as: node install-run-rush.js <args>')
}

Type guard

function invokedAsScript(argv: string[]): boolean {
  return Array.isArray(argv) && argv.length >= 2 &&
    Boolean(argv[0]) && Boolean(argv[1])
}

Prevention

When it happens

Trigger: process.argv has fewer than 2 entries when install-run-rush.js executes — e.g. the script is embedded/executed in an environment that strips argv (custom embedders, bundled workers, unusual spawnSync with empty args array).

Common situations: Invoking the script via a non-standard runner or embedding tool that rewrites argv; spawning node with an argv array that omits the script path; tooling that concatenates scripts and drops the entry argv.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/fd33cd476a3ab45a. Report an issue: GitHub.