hcengineering/platform · error · Error

Unexpected exception: could not detect node path

Error message

Unexpected exception: could not detect node path

What it means

_run is the CLI entry point of install-run.js; it destructures process.argv expecting argv[0] to be the node executable path. If nodePath is missing/empty — which should never happen in a normally spawned node process — it throws 'Unexpected exception: could not detect node path' to fail loudly on an unexpected runtime environment.

Source

Thrown at foundations/core/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: `node <path>/install-run.js <packageSpec> <bin> [args...]` so argv[0] is the node path.
  2. If embedding the module, ensure process.argv[0] is set or gate _run so it isn't executed on import.
  3. Check any wrapper/launcher code that rewrites or truncates process.argv before requiring the script.
  4. Upgrade to a standard Node runtime (not a stripped embedded build) to execute the bootstrap script.

Example fix

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

Strategy: validation

Validate before calling

// Before requiring/executing the bootstrap script, ensure argv looks like a normal node invocation:
if (!process.argv[0] || !process.argv[1]) {
  process.argv = [process.execPath, ...process.argv.filter(Boolean)];
}

Type guard

function hasNodePathInArgv(argv) {
  return Array.isArray(argv) && typeof argv[0] === 'string' && argv[0].length > 0;
}

Try / catch

try {
  require('./install-run.js'); // executes _run when invoked as a script
} catch (e) {
  if (/could not detect node path/.test(e.message)) {
    console.error('process.argv[0] was empty; run the script via `node install-run.js ...` or set process.argv correctly.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking the script in a way where process.argv[0] is falsy: embedding/evaluating the module in a nonstandard runtime, custom launchers that strip argv, or test harnesses that stub process.argv with an empty array before requiring the script.

Common situations: Bundling or importing install-run.js into another tool that executes _run with a manipulated argv; exotic embedded Node runtimes; misconfigured wrappers that call the script without the node binary in argv.

Related errors


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