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
- Read the npm output above this error — it contains the real cause; fix that (404, ETIMEDOUT, E401, ERESOLVE, etc.).
- Verify registry connectivity and authentication (.npmrc / NODE_AUTH_TOKEN) in the environment running the script.
- Re-run after transient network failures; clear a suspect npm cache ('npm cache clean --force') or set a working proxy.
- 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
- Configure .npmrc auth tokens and proxies in CI before the install step.
- Use 'npm ping' / 'npm view' as a preflight connectivity check.
- Cache node_modules or the npm cache to reduce network flakiness.
- Always read the inherited npm output above the error — the message itself is generic by design.
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
- "npm ${command}" encountered an error
- "npm view" returned error code ${npmVersionSpawnResult.statu
- Unable to resolve version ${version} of package ${name}: ${e
- "npm ${command}" encountered an error
- Unable to install package: ${e}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/6e39dbfab0f66dd6.
Report an issue: GitHub.