hcengineering/platform · error

Unexpected exception: could not detect node path

Error message

Unexpected exception: could not detect node path

What it means

_run() destructures process.argv expecting argv[0] to be the node executable path. If it is missing or empty — which should never happen under a normal node launch — the script throws, indicating the process was started in a way that corrupted argv.

Source

Thrown at foundations/net/common/scripts/install-run.js:746

    }
    else {
        throw result.error || new Error('An unknown error occurred.');
    }
}
function runWithErrorAndStatusCode(logger, fn) {
    process.exitCode = 1;
    try {
        const exitCode = fn();
        process.exitCode = exitCode;
    }
    catch (e) {
        logger.error('\n\n' + e.toString() + '\n\n');
    }
}
function _run() {
    const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, rawPackageSpecifier /* qrcode@^1.2.0 */, packageBinName /* qrcode */, ...packageBinArgs /* [-f, myproject/lib] */] = process.argv;
    if (!nodePath) {
        throw new Error('Unexpected exception: could not detect node path');
    }
    if (path__WEBPACK_IMPORTED_MODULE_3__.basename(scriptPath).toLowerCase() !== 'install-run.js') {
        // If install-run.js wasn't directly invoked, don't execute the rest of this function. Return control
        // to the script that (presumably) imported this file
        return;
    }
    if (process.argv.length < 4) {
        console.log('Usage: install-run.js <package>@<version> <command> [args...]');
        console.log('Example: install-run.js qrcode@1.2.2 qrcode https://rushjs.io');
        process.exit(1);
    }
    const logger = { info: console.log, error: console.error };
    runWithErrorAndStatusCode(logger, () => {
        const rushJsonFolder = findRushJsonFolder();
        const rushCommonFolder = _ensureAndJoinPath(rushJsonFolder, 'common');
        const packageSpecifier = _parsePackageSpecifier(rawPackageSpecifier);
        const name = packageSpecifier.name;
        const version = _resolvePackageVersion(logger, rushCommonFolder, packageSpecifier);

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Launch the script normally: `node common/scripts/install-run.js <pkg>@<ver> <bin> [args]` so argv[0] is the node path.
  2. If wrapping the script, keep process.argv[0] set to the node executable path.
  3. Audit code that mutates process.argv before the script runs.
  4. Check that the entrypoint wrapper (e.g. install-run-rush.js) is being executed by node, not sourced or embedded incorrectly.

Example fix

// before: wrapper clobbers argv
process.argv = [scriptPath, ...args];
require('./install-run');
// after: keep node path as argv[0]
process.argv = [process.execPath, scriptPath, ...args];
require('./install-run');
Defensive patterns

Strategy: validation

Validate before calling

if (!process.argv[0] || !process.argv[0].endsWith('node')) {
  throw new Error('Script must be launched via `node <script>` so argv[0] is the node path');
}
// run only after this check
runScript(process.argv.slice(2));

Prevention

When it happens

Trigger: Invoking the script through an unusual launcher that strips or replaces process.argv[0], embedding the script in a runtime where argv is manually constructed and nodePath is undefined, or calling _run()/module top-level code from a non-CLI context.

Common situations: Custom Electron/embedded-node launches with hand-built argv arrays; wrappers that do `process.argv = [...]` before importing the script; exotic sandboxes that launch scripts without a node binary path.

Related errors


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