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 entrypoint of install-run-rush.js destructures process.argv expecting [nodePath, scriptPath, ...args]. If either nodePath or scriptPath is falsy — meaning the script was not invoked the normal way (node install-run-rush.js ...) — it throws this error before selecting the rush/rushx binary.

Source

Thrown at foundations/utils/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. Run the script with node explicitly: node common/scripts/install-run-rush.js <args>
  2. Ensure a proper shebang (#!/usr/bin/env node) if executing it directly
  3. Inspect process.argv in your wrapper to confirm nodePath and scriptPath are present

Example fix

// before
./common/scripts/install-run-rush.js build --to myproject
// after
node ./common/scripts/install-run-rush.js build --to myproject
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

null

Try / catch

try {
  runRushScript()
} catch (e) {
  if (String(e.message).includes('could not detect node path or script path')) {
    console.error('Invoke with: node common/scripts/install-run-rush.js <rush args>')
    process.exit(1)
  }
  throw e
}

Prevention

When it happens

Trigger: Executing install-run-rush.js without a node interpreter in argv (e.g. chmod +x and running it directly without a shebang, or embedding it in a context that strips argv), so process.argv[1]/[2] are missing or empty.

Common situations: Invoking the script via a non-standard runner; copying the script into an environment where argv shape differs; calling it through a wrapper that mangles process.argv.

Related errors


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