hcengineering/platform · error
"npm ${command}" encountered an error
Error message
"npm ${command}" encountered an error What it means
_installPackage spawns `npm <command>` (typically 'install') in the package install folder with stdio inherit. If the spawned npm exits with a non-zero status, it throws '"npm ${command}" encountered an error'. This signals the npm subprocess itself failed; the real npm output is shown above this message because stdio is inherited.
Source
Thrown at foundations/utils/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 full npm output printed before this error — it contains the actual failure (ERESOLVE, 404, network)
- Fix network/proxy settings (HTTP_PROXY/HTTPS_PROXY, .npmrc registry) and retry
- Clear the npm cache if it is corrupted: `npm cache clean --force`
- Choose a package version compatible with your Node engine and dependency tree
Example fix
// before: proxy not configured in CI // after env: HTTP_PROXY: http://proxy.corp:8080 HTTPS_PROXY: http://proxy.corp:8080 node common/scripts/install-run.js pnpm install
Defensive patterns
Strategy: retry
Validate before calling
const { execSync } = require('child_process');
function preflightNpmInstall(name, version) {
execSync(`npm view ${name}@${version} version`, { stdio: 'inherit' }); // reachable registry + existing version
}
preflightNpmInstall('pnpm', '9.15.0'); Try / catch
try {
installAndRun(logger, packageDir, name, version, command);
} catch (e) {
if (e.message.includes('encountered an error')) {
console.error('npm install failed; see npm output above for the real cause (ERESOLVE, 404, network)');
process.exit(1);
}
throw e;
} Prevention
- Always read the npm output printed above the error — stdio is inherited
- Configure proxy/auth env vars in CI before installing
- Keep the npm cache healthy (`npm cache verify`)
- Pick versions compatible with your Node engine
When it happens
Trigger: spawnSync(npmPath, [command, ...], {cwd: packageInstallFolder}) returns status !== 0 during installAndRun — npm install of the requested package failed for network, registry-auth, peer-conflict, or platform reasons.
Common situations: Corporate proxies blocking registry access; engine incompatibility (package requires different Node); ERESOLVE peer dependency conflicts; npm cache corruption (EACCES in ~/.npm).
Related errors
- "npm ${command}" encountered an error
- "npm ${command}" encountered an error
- Unable to install package: ${e}
- "npm view" returned error code ${npmVersionSpawnResult.statu
- Unable to resolve version ${version} of package ${name}: ${e
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/85de5f6cdcbd5471.
Report an issue: GitHub.