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-range> version --json` to resolve a version range to the latest satisfying version. A nonzero exit status from that spawnSync throws this error with the status code. It means npm itself failed to query the registry.

Source

Thrown at foundations/communication/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

  1. Run `npm view <name>@<version> version` manually to see the underlying npm error.
  2. Verify network/proxy access to the npm registry (npm config get proxy, registry URL).
  3. If it's a private package, configure the .npmrc auth token for its scope.
  4. Check that the package name and version range are correct and exist in the registry.

Example fix

// before (no auth for private scope)
node install-run.js @mycorp/cli@1.2.0 -- some-cmd
// after: add registry auth first
npm config set @mycorp:registry https://npm.mycorp.com
npm login --scope=@mycorp
node install-run.js @mycorp/cli@1.2.0 -- some-cmd
Defensive patterns

Strategy: retry

Validate before calling

const name = 'pnpm'; // verify before invoking install-run
require('child_process').execSync(`npm view ${name}@8 version`, { stdio: 'inherit' });

Try / catch

try { runInstall(); } catch (e) { if (/"npm view" returned error code/.test(e.message)) { await new Promise(r => setTimeout(r, 5000)); /* retry up to 3x for transient registry/network issues */ } else throw e; }

Prevention

When it happens

Trigger: `npm view` exits nonzero because the package or version range does not exist, the registry is unreachable, npm is misconfigured (bad registry URL, auth required for a private package), or network is down.

Common situations: Typo in package name; private scoped package without registry auth token; corporate proxy/firewall blocking registry.npmjs.org; npm registry outage; specifying a version range that matches nothing.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/3d8a10f8bb02935a. Report an issue: GitHub.