hcengineering/platform · error

Unable to install package: ${e}

Error message

Unable to install package: ${e}

What it means

Catch-all wrapper in _installPackage: any exception thrown while running the npm command — including the non-zero-exit error and spawn failures like ENOENT (npm not found) — is rethrown as "Unable to install package: <e>". The original message is preserved in the suffix, so inspect it for the underlying cause.

Source

Thrown at foundations/server/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. Ensure npm is installed and on PATH (npm -v) in the environment running the script
  2. Read the wrapped cause after the colon and apply its specific fix (registry, lockfile, permissions)
  3. Delete common/temp/install-run to force a clean re-install, then retry
  4. Pin/upgrade Node.js to a version that ships a compatible npm

Example fix

// before (npm missing in CI image)
image: node-slim-without-npm
// after
image: node:20  # includes npm on PATH
Defensive patterns

Strategy: try-catch

Validate before calling

const { execSync } = require('child_process')
try { execSync('npm -v', { stdio: 'ignore' }) } catch { throw new Error('npm is not available on PATH') }

Try / catch

try {
  installAndRun(logger, pkg, version, bin, args)
} catch (e) {
  const cause = e.message.replace('Unable to install package: ', '')
  if (cause.includes('ENOENT')) throw new Error('npm not found on PATH; install Node.js/npm')
  throw e
}

Prevention

When it happens

Trigger: The `npm` executable is missing from PATH (spawn ENOENT) or not executable on the chosen shell; npm exits non-zero; the spawn itself throws (permissions, bad cwd).

Common situations: Minimal CI images without npm installed; Windows _isWindows() shell behavior with unusual PATH; corrupted install folder after a previous failed run.

Related errors


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