hcengineering/platform · error · 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 and argv[1] to be this script's path. If either is missing/empty, it cannot determine which rush binary (rush vs rushx) to launch and throws immediately before doing any work.

Source

Thrown at foundations/core/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 <args> so argv contains node path and script path
  2. Fix any wrapper/bootstrap that strips or rewrites process.argv before requiring the script
  3. Update your Node runtime if a broken custom runner is trimming argv

Example fix

// before
node -e "require('./common/scripts/install-run-rush.js')" build
// after
node common/scripts/install-run-rush.js build
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

try { runRushLauncher(); }
catch (e) { if (/could not detect node path or script path/.test(e.message)) { console.error('Invoke via: node common/scripts/install-run-rush.js <args>'); } else throw e; }

Prevention

When it happens

Trigger: Invoking install-run-rush.js in an environment where process.argv lacks the node path or script path (e.g. embedded/custom runtime, unusual embedding where argv was trimmed or replaced).

Common situations: Running the script through a wrapper that mangles argv; exotic execution contexts (embedded V8, custom REPL) rather than a normal `node install-run-rush.js ...` invocation.

Related errors


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