hcengineering/platform · error

"npm ${command}" encountered an error

Error message

"npm ${command}" encountered an error

What it means

_installPackage spawns 'npm install' (or another package manager command) with stdio 'inherit' in the package install folder and checks the exit code; a non-zero status means npm failed, so the generic message '"npm <command>" encountered an error' is thrown. Since output is inherited, the actual npm failure details appear in the console immediately before this error.

Source

Thrown at foundations/net/common/scripts/install-run.js:644

        throw new Error(`Unable to create package.json: ${e}`);
    }
}
/**
 * Run "npm install" in the package install folder.
 */
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.
 */

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Read the npm output above this error — it contains the real cause; fix that (404, ETIMEDOUT, E401, ERESOLVE, etc.).
  2. Verify registry connectivity and authentication (.npmrc / NODE_AUTH_TOKEN) in the environment running the script.
  3. Re-run after transient network failures; clear a suspect npm cache ('npm cache clean --force') or set a working proxy.
  4. Confirm the requested package@version is publishable/resolvable ('npm view <name>@<version>').
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check registry reachability and auth before invoking
const { execSync } = require('child_process');
try {
  execSync('npm ping', { stdio: 'ignore' });
  execSync(`npm view ${name}@${version} version`, { stdio: 'ignore' });
} catch (e) {
  throw new Error(`Registry or package unreachable before install: ${e.message}`);
}

Try / catch

let attempts = 3;
while (attempts--) {
  try {
    runInstallRun(name, version);
    break;
  } catch (e) {
    if (/"npm .*" encountered an error/.test(e.message) && attempts > 0 && isTransient(e)) continue;
    console.error(e.message + '\nSee npm output above for the real failure.');
    process.exit(1);
  }
}

Prevention

When it happens

Trigger: installAndRun → _installPackage, when the child npm process exits non-zero: registry unreachable/unauthorized, network timeouts, package/version not found in the registry, incompatible peer dependencies, or npm itself crashing.

Common situations: CI runners without npm credentials for a private registry; offline/air-gapped environments; proxy/firewall blocking registry.npmjs.org; corrupted npm cache; the pinned package version no longer existing.

Related errors


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