hcengineering/platform · error · Error

Unable to install package: ${e}

Error message

Unable to install package: ${e}

What it means

This is the outer wrapper in _installPackage: any exception thrown during the npm spawn-and-check sequence — including error 44 ('npm <command> encountered an error') and spawn-time failures like ENOENT when npm is missing — is rethrown as 'Unable to install package: <e>'. It signals the bootstrap install of the requested package (e.g. rush itself or a tool like qrcode) could not be completed.

Source

Thrown at foundations/core/common/scripts/install-run.js:649

 */
function _installPackage(logger, packageInstallFolder, name, version, command) {
    try {
        logger.info(`Installing ${name}...`);
        const npmPath = getNpmPath();
        const platformNpmPath = _getPlatformPath(npmPath);
        const result = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, [command], {
            stdio: 'inherit',
            cwd: packageInstallFolder,
            env: process.env,
            shell: _isWindows()
        });
        if (result.status !== 0) {
            throw new Error(`"npm ${command}" encountered an error`);
        }
        logger.info(`Successfully installed ${name}@${version}`);
    }
    catch (e) {
        throw new Error(`Unable to install package: ${e}`);
    }
}
/**
 * Get the ".bin" path for the package.
 */
function _getBinPath(packageInstallFolder, binName) {
    const binFolderPath = path__WEBPACK_IMPORTED_MODULE_3__.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME, '.bin');
    const resolvedBinName = _isWindows() ? `${binName}.cmd` : binName;
    return path__WEBPACK_IMPORTED_MODULE_3__.resolve(binFolderPath, resolvedBinName);
}
/**
 * Returns a cross-platform path - windows must enclose any path containing spaces within double quotes.
 */
function _getPlatformPath(platformPath) {
    return _isWindows() && platformPath.includes(' ') ? `"${platformPath}"` : platformPath;
}
function _isWindows() {
    return os__WEBPACK_IMPORTED_MODULE_2__.platform() === 'win32';

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Inspect the nested cause in the message; address the underlying npm failure first.
  2. Confirm node and npm are on PATH in the environment running the script (`which npm`).
  3. Clear the npm cache (`npm cache verify` or `npm cache clean --force`) if corruption is suspected.
  4. Remove common/temp/install-run-* and rerun for a clean bootstrap.

Example fix

// before
node install-run.js qrcode@^1.2.0 qrcode -f x
// after
rm -rf common/temp/install-run-* && npm cache verify && node install-run.js qrcode@^1.2.0 qrcode -f x
Defensive patterns

Strategy: try-catch

Validate before calling

const { execSync } = require('child_process');
const fs = require('fs');
function assertInstallPreconditions() {
  execSync('node --version');
  execSync('npm --version'); // throws ENOENT if npm missing
  fs.accessSync('common/temp', fs.constants.W_OK);
}
assertInstallPreconditions();

Try / catch

try {
  installAndRun(logger, name, version, bin, args);
} catch (e) {
  console.error(`Bootstrap install failed: ${e.message}`); // e.message contains the nested cause
  if (/ENOENT/.test(e.message)) console.error('npm not found on PATH');
  if (/network|ETIMEDOUT|ECONNREFUSED/.test(e.message)) console.error('Check registry/proxy connectivity');
  throw e;
}

Prevention

When it happens

Trigger: installAndRun calls _installPackage and either the child npm process exits non-zero (status !== 0) or the spawn itself throws (npm not on PATH, permission denied executing npm, ENOSPC).

Common situations: Same root causes as npm failures: network/proxy issues, bad lockfiles, missing Node/npm in CI images, corrupted npm cache (~/.npm), or a broken common/temp install folder.

Related errors


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