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` via spawnSync to expand a version range to the latest matching version. If the spawn exits with a nonzero status, the script throws this error with the exit code.

Source

Thrown at foundations/server/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>@<range> version` manually with the same npm to see the real error
  2. Verify registry/auth: ensure .npmrc has a valid token for private packages (npm login)
  3. Check network/proxy settings (npm config get proxy, https-proxy) and that the registry URL is correct
  4. Confirm the package name/version range actually exists on the registry

Example fix

// before (.npmrc missing token for private registry)
registry=https://registry.mycompany.io/
// after
registry=https://registry.mycompany.io/
//registry.mycompany.io/:_authToken=${NPM_TOKEN}
Defensive patterns

Strategy: retry

Validate before calling

// preflight registry access and auth
try {
  child_process.execSync(`npm view ${name} version --no-update-notifier`, { stdio: [] });
} catch { throw new Error(`Cannot reach registry for ${name}; check network/.npmrc auth`); }

Type guard

null

Try / catch

try {
  runRushInstall();
} catch (e) {
  if (String(e).includes('"npm view" returned error code')) {
    // retry with backoff for transient network failures
    await new Promise(r => setTimeout(r, 5000));
    return runRushInstall();
  } else throw e;
}

Prevention

When it happens

Trigger: Package name/version does not exist in the configured registry; network is down or registry unreachable; auth required for a private registry (401/403); npm itself fails to launch (exit code from npm CLI); offline npm config with no cache hit.

Common situations: Private registry packages queried without .npmrc auth tokens; typo'd package name in install-run-rushx wrapper constants; corporate proxy/firewall blocking registry.npmjs.org; npm configured against a deprecated/internal registry URL.

Related errors


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