hcengineering/platform · error

Unable to install package: ${e}

Error message

Unable to install package: ${e}

What it means

This is the catch-all wrapper of _installPackage: any exception in the install flow — including the non-zero npm exit (268) and spawnSync-level failures like ENOENT — is rethrown as 'Unable to install package: ${e}'. The wrapped cause plus the inherited npm output identify the underlying problem.

Source

Thrown at foundations/utils/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 wrapped cause (`: ${e}`) and the npm output above it to find the root failure
  2. Retry after fixing network/proxy/registry configuration if the cause is transient
  3. Delete the package install folder (and rush-recycler leftovers) so the next run starts clean
  4. Ensure Node/npm are healthy: `npm doctor` in the CI environment

Example fix

// decode then fix
// before: Unable to install package: "npm install" encountered an error
// after: fix the shown npm failure (e.g. pin resolvable version)
node common/scripts/install-run.js pnpm 9.15.0 -- pnpm install
Defensive patterns

Strategy: try-catch

Try / catch

try {
  installAndRun(logger, packageDir, name, version, command);
} catch (e) {
  if (String(e.message).startsWith('Unable to install package')) {
    const cause = String(e.message).replace('Unable to install package: ', '');
    console.error(`Install of ${name}@${version} failed: ${cause}`);
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Any throw inside _installPackage during installAndRun: npm subprocess exits non-zero, npm binary cannot be spawned, or the install folder is unwritable.

Common situations: Same causes as 268 (network, auth, peer conflicts) plus spawn-level failures such as a deleted npm binary mid-run or ENOENT from a broken PATH.

Related errors


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