hcengineering/platform · error

Unexpected exception: could not detect node path

Error message

Unexpected exception: could not detect node path

What it means

The _run entry point destructures process.argv expecting argv[0] to be the node executable path. In a normal Node process this is always present; if it is somehow missing, the script throws 'Unexpected exception: could not detect node path'. It is a defensive sanity check, so hitting it indicates a very unusual execution environment.

Source

Thrown at foundations/server/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. Run the script normally via node so process.argv[0] exists (node install-run.js <pkg> <version> <bin> [args...])
  2. Do not stub or clear process.argv before importing/invoking the module
  3. If embedding, pass a synthetic argv with the node path as the first element

Example fix

// before (test stub)
process.argv = []
await import('./install-run.js')
// after
process.argv = [process.execPath, 'install-run.js', 'qrcode', '^1.2.0', 'qrcode']
Defensive patterns

Strategy: validation

Validate before calling

if (!process.argv[0]) throw new Error('process.argv[0] (node path) missing; run via node')

Type guard

function hasNodePath(argv: string[]): argv is [string, ...string[]] {
  return argv.length > 0 && !!argv[0]
}

Prevention

When it happens

Trigger: Embedding or importing the script in a context where process.argv is empty or was replaced (custom runtimes, workers, bundled environments that strip argv); invoking Node in a way that omits argv[0].

Common situations: Embedding install-run.js inside another tool that fakes process.argv; exotic embedded JS runtimes; test harnesses that stub process.argv with an empty array.

Related errors


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