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` to resolve a version range to the latest satisfying version. A non-zero exit status from that spawned npm process throws this error with the exit code. It indicates npm itself failed to query the registry, not that parsing failed.
Source
Thrown at foundations/utils/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
- Verify network access to the configured registry: `npm view <package> version` manually with the same npm
- Check the package name and version range for typos or a range matching no published version
- Configure registry credentials (NPM_TOKEN / .npmrc) if the package is private
- Check registry status (npmjs.com status page) and retry if it is an outage
Example fix
// before: private package, no auth in CI
npm view @myorg/private-pkg@^1.0.0 version -> E404
// after
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# plus .npmrc: //registry.npmjs.org/:_authToken=${NPM_TOKEN} Defensive patterns
Strategy: retry
Validate before calling
const { execSync } = require('child_process');
function assertRegistryReachable(name) {
execSync(`npm view ${name} version --no-update-notifier`, { stdio: 'inherit' });
}
assertRegistryReachable('pnpm'); // fails fast with npm's own diagnostics Try / catch
try {
installAndRun(logger, packageDir, name, version, command);
} catch (e) {
if (/"npm view" returned error code/.test(e.message)) {
// transient registry/network issue: retry with backoff
}
throw e;
} Prevention
- Configure registry auth (.npmrc + NPM_TOKEN) for private packages before running
- Set HTTP(S)_PROXY in restricted networks
- Pin versions that are known to exist on the registry
When it happens
Trigger: spawnSync of the platform npm path with ['view', `${name}@${version}`, 'version', ...] returns status !== 0, e.g. package/version range not found, no network to the registry, registry authentication required, or npm crashes.
Common situations: Offline CI or blocked registry host (corporate proxy/firewall); typo in the package name or an impossible version range; private registry package requiring credentials (NPM_TOKEN missing); registry outage.
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/7f49369a64f8e413.
Report an issue: GitHub.