{"record":{"id":"d6ec1738b9540b6f","repo":"hcengineering/platform","slug":"npm-view-returned-error-code-npmversionspawnre-d6ec17","errorCode":null,"errorMessage":"\"npm view\" returned error code ${npmVersionSpawnResult.status}","messagePattern":"\"npm view\" returned error code (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/net/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/net/common/scripts/install-run.js#L487-L523","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnode install-run.js rush@latest   # registry unreachable -> npm view exits 1\n// after\nnode install-run.js rush@5.62.0   # exact version, no registry lookup needed","handlingStrategy":"retry","validationCode":"const { status } = spawnSync('npm', ['view', `${name}@${range}`, 'version', '--no-update-notifier'], { stdio: 'ignore' })\nif (status !== 0) console.warn('Registry lookup will fail — pin an exact version or fix registry access')","typeGuard":null,"tryCatchPattern":"const MAX = 3\nfor (let i = 1; i <= MAX; i++) {\n  try { return resolvePackageVersion(name, version) }\n  catch (e) {\n    if (!/npm view.*error code/.test(e.message) || i === MAX) throw e\n    await new Promise(r => setTimeout(r, 2 ** i * 500)) // backoff for transient registry/network issues\n  }\n}","preventionTips":["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."],"tags":["npm","network","registry"],"backgroundTag":"npm-view-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}