hcengineering/platform · error · Error
"npm view" returned error code ${npmVersionSpawnResult.statu
Error message
"npm view" returned error code ${npmVersionSpawnResult.status} What it means
_resolvePackageVersion shells out to `npm view <name>@<version> version --json` to resolve the latest version satisfying a range. If the spawned npm exits with a non-zero status, the script throws this error with the exit code, before attempting to parse output.
Source
Thrown at foundations/core/common/scripts/install-run.js:505
// ]
// ```
//
// if multiple versions match the selector, or
//
// ```
// "3.0.0"
// ```
//
// if only a single version matches.
const spawnSyncOptions = {
cwd: rushTempFolder,
stdio: [],
shell: _isWindows()
};
const platformNpmPath = _getPlatformPath(npmPath);
const npmVersionSpawnResult = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier', '--json'], spawnSyncOptions);
if (npmVersionSpawnResult.status !== 0) {
throw new Error(`"npm view" returned error code ${npmVersionSpawnResult.status}`);
}
const npmViewVersionOutput = npmVersionSpawnResult.stdout.toString();
const parsedVersionOutput = JSON.parse(npmViewVersionOutput);
const versions = Array.isArray(parsedVersionOutput)
? parsedVersionOutput
: [parsedVersionOutput];
let latestVersion = versions[0];
for (let i = 1; i < versions.length; i++) {
const latestVersionCandidate = versions[i];
if (_compareVersionStrings(latestVersionCandidate, latestVersion) > 0) {
latestVersion = latestVersionCandidate;
}
}
if (!latestVersion) {
throw new Error('No versions found for the specified version range.');
}
return latestVersion;
}View on GitHub (pinned to 63e28dc964)
Solutions
- Run `npm view <name>@<range> version` manually to see the underlying registry error
- Fix .npmrc registry/auth for private packages (and ensure the syncNpmrc step has the needed env vars)
- Check network/proxy/VPN connectivity to the npm registry in CI
- Verify the package name and version range are correct
Example fix
// before node install-run-rush.js # fails: npm view returned error code 1 // after npm view @microsoft/rush@^5.0.0 version # diagnose; fix .npmrc authToken or network, then retry
Defensive patterns
Strategy: retry
Validate before calling
const probe = child_process.spawnSync('npm', ['ping', '--registry', registry], { stdio: [] });
if (probe.status !== 0) throw new Error('npm registry unreachable or unauthorized: ' + probe.stderr); Try / catch
try { resolveVersion(name, range); }
catch (e) { if (/"npm view" returned error code/.test(e.message)) { console.error('Check registry connectivity/auth for ' + name + ' (exit ' + e.message + ')'); if (isTransient(e)) await retry(() => resolveVersion(name, range), 3); } else throw e; } Prevention
- Pre-warm CI with registry auth in .npmrc before rush bootstrap
- Verify `npm view <pkg> version` works in the same environment
- Configure proxy/VPN settings for npm in air-gapped networks
When it happens
Trigger: npm view fails because the package/version range doesn't exist, the registry is unreachable or returns 4xx/5xx, auth is required but missing, or npm itself errors (bad config, proxy failure).
Common situations: Offline/air-gapped CI without registry access; private registry auth missing in .npmrc; typo'd package name; proxy/firewall blocking registry.npmjs.org.
Related errors
- "npm view" returned error code ${npmVersionSpawnResult.statu
- "npm view" returned error code ${npmVersionSpawnResult.statu
- "npm view" returned error code ${npmVersionSpawnResult.statu
- "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/f8b0504a62809c7f.
Report an issue: GitHub.