{"record":{"id":"f8b0504a62809c7f","repo":"hcengineering/platform","slug":"npm-view-returned-error-code-npmversionspawnre-f8b050","errorCode":null,"errorMessage":"\"npm view\" returned error code ${npmVersionSpawnResult.status}","messagePattern":"\"npm view\" returned error code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/common/scripts/install-run.js","lineNumber":505,"sourceCode":"            // ]\n            // ```\n            //\n            // if multiple versions match the selector, or\n            //\n            // ```\n            // \"3.0.0\"\n            // ```\n            //\n            // if only a single version matches.\n            const spawnSyncOptions = {\n                cwd: rushTempFolder,\n                stdio: [],\n                shell: _isWindows()\n            };\n            const platformNpmPath = _getPlatformPath(npmPath);\n            const npmVersionSpawnResult = child_process__WEBPACK_IMPORTED_MODULE_0__.spawnSync(platformNpmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier', '--json'], spawnSyncOptions);\n            if (npmVersionSpawnResult.status !== 0) {\n                throw new Error(`\"npm view\" returned error code ${npmVersionSpawnResult.status}`);\n            }\n            const npmViewVersionOutput = npmVersionSpawnResult.stdout.toString();\n            const parsedVersionOutput = JSON.parse(npmViewVersionOutput);\n            const versions = Array.isArray(parsedVersionOutput)\n                ? parsedVersionOutput\n                : [parsedVersionOutput];\n            let latestVersion = versions[0];\n            for (let i = 1; i < versions.length; i++) {\n                const latestVersionCandidate = versions[i];\n                if (_compareVersionStrings(latestVersionCandidate, latestVersion) > 0) {\n                    latestVersion = latestVersionCandidate;\n                }\n            }\n            if (!latestVersion) {\n                throw new Error('No versions found for the specified version range.');\n            }\n            return latestVersion;\n        }","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/common/scripts/install-run.js#L487-L523","documentation":"_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.","triggerScenarios":"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).","commonSituations":"Offline/air-gapped CI without registry access; private registry auth missing in .npmrc; typo'd package name; proxy/firewall blocking registry.npmjs.org.","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"],"exampleFix":"// before\nnode install-run-rush.js  # fails: npm view returned error code 1\n// after\nnpm view @microsoft/rush@^5.0.0 version  # diagnose; fix .npmrc authToken or network, then retry","handlingStrategy":"retry","validationCode":"const probe = child_process.spawnSync('npm', ['ping', '--registry', registry], { stdio: [] });\nif (probe.status !== 0) throw new Error('npm registry unreachable or unauthorized: ' + probe.stderr);","typeGuard":null,"tryCatchPattern":"try { resolveVersion(name, range); }\ncatch (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; }","preventionTips":["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"],"tags":["npm","registry","network","spawn"],"backgroundTag":"npm-view-registry-failure","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}