hcengineering/platform · error · Error

Unexpected exception: could not detect node path

Error message

Unexpected exception: could not detect node path

What it means

install-run.js's `_run()` destructures process.argv expecting argv[0] to be the node executable path and argv[1] to be the script path. If argv[0] (nodePath) is missing/falsy, it throws this Error — it indicates a broken invocation environment rather than a user error in the package spec.

Source

Thrown at foundations/communication/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 as a CLI: `node common/scripts/install-run.js ...` so argv[0] is the node binary.
  2. Don't import/install-run as a module from node -e or REPL contexts; if you need the logic programmatically, call installAndRun directly instead of _run.
  3. Check the launcher (shell wrapper, pm2, node fork with execArgv) isn't clearing process.argv[0].
  4. Verify you're using a standard Node build; try the official node binary to rule out an embedded runtime.

Example fix

// before
node -e "require('./common/scripts/install-run.js')" qrcode@1.4.2 qrcode
// Error: Unexpected exception: could not detect node path
// after
node ./common/scripts/install-run.js qrcode@1.4.2 qrcode
Defensive patterns

Strategy: validation

Validate before calling

if (!process.argv[0] || !process.argv[0].endsWith('node')) {
  throw new Error('Run install-run.js via the node CLI, not via -e/REPL/embedded runtime')
}

Try / catch

try {
  await runBootstrap()
} catch (e) {
  if (String(e).includes('could not detect node path')) {
    console.error('Invoke as: node common/scripts/install-run.js <pkg> <bin> [args]')
  }
  throw e
}

Prevention

When it happens

Trigger: Executing the script in an environment where process.argv[0] is empty or stripped: embedding the script as a REPL/module evaluation (node -e, node --eval), unusual embedders/forks of Node that set argv[0] to empty, or launching via a tool that rewrites argv.

Common situations: Running install-run.js via node -e 'require(...)' or programmatic imports instead of as a CLI script; custom embedded Node runtimes; patched launchers that pass empty argv[0]. Note the script also early-returns if the basename isn't install-run.js, so direct imports normally don't reach this throw.

Related errors


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