hcengineering/platform · error
"npm view" returned error code ${npmVersionSpawnResult.statu
Error message
"npm view" returned error code ${npmVersionSpawnResult.status} What it means
_resolvePackageVersion runs `npm view <name>@<version> version --json` (spawnSync) to translate a version range like ^4.0.0 into the latest concrete version. If npm exits non-zero — the package doesn't exist, the range matches nothing, or the registry is unreachable — this Error is thrown with npm's exit status.
Source
Thrown at foundations/net/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
- Inspect npm's stderr — run `npm view <name>@<version> version` manually to see the real cause.
- Pin an exact version (e.g. rush@5.62.0 instead of ^5.62.0) to skip registry resolution entirely (uses local lockless install of that version).
- Fix registry connectivity/auth: check .npmrc registry URL, proxy settings, and NPM_TOKEN validity.
- Retry if the failure was transient network/registry flakiness.
Example fix
// before node install-run.js rush@latest # registry unreachable -> npm view exits 1 // after node install-run.js rush@5.62.0 # exact version, no registry lookup needed
Defensive patterns
Strategy: retry
Validate before calling
const { status } = spawnSync('npm', ['view', `${name}@${range}`, 'version', '--no-update-notifier'], { stdio: 'ignore' })
if (status !== 0) console.warn('Registry lookup will fail — pin an exact version or fix registry access') Try / catch
const MAX = 3
for (let i = 1; i <= MAX; i++) {
try { return resolvePackageVersion(name, version) }
catch (e) {
if (!/npm view.*error code/.test(e.message) || i === MAX) throw e
await new Promise(r => setTimeout(r, 2 ** i * 500)) // backoff for transient registry/network issues
}
} Prevention
- Pin exact versions in bootstrap invocations to avoid registry lookups entirely.
- Verify registry connectivity and .npmrc registry/proxy settings in CI images.
- Keep NPM_TOKEN fresh for private registries.
- Retry transient failures with backoff; npm view flakiness is common on shared runners.
When it happens
Trigger: The install-run script is given a non-exact version (e.g. rush@^5.62.0) forcing registry resolution, and spawnSync's npm view returns status !== 0: unknown package, no matching version, network/auth failure against the registry, or npm itself erroring.
Common situations: Corporate proxy/VPN blocking registry.npmjs.org; .npmrc pointing at a private registry that lacks the package; a typo'd package name; offline CI; npm auth token expired for a private registry.
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/d6ec1738b9540b6f.
Report an issue: GitHub.