{"record":{"id":"d117c31e7776a692","repo":"hcengineering/platform","slug":"npm-view-returned-error-code-npmversionspawnre-d117c3","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/server/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/server/common/scripts/install-run.js#L487-L523","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `npm view <name>@<range> version` manually with the same npm to see the real error","Verify registry/auth: ensure .npmrc has a valid token for private packages (npm login)","Check network/proxy settings (npm config get proxy, https-proxy) and that the registry URL is correct","Confirm the package name/version range actually exists on the registry"],"exampleFix":"// before (.npmrc missing token for private registry)\nregistry=https://registry.mycompany.io/\n// after\nregistry=https://registry.mycompany.io/\n//registry.mycompany.io/:_authToken=${NPM_TOKEN}","handlingStrategy":"retry","validationCode":"// preflight registry access and auth\ntry {\n  child_process.execSync(`npm view ${name} version --no-update-notifier`, { stdio: [] });\n} catch { throw new Error(`Cannot reach registry for ${name}; check network/.npmrc auth`); }","typeGuard":"null","tryCatchPattern":"try {\n  runRushInstall();\n} catch (e) {\n  if (String(e).includes('\"npm view\" returned error code')) {\n    // retry with backoff for transient network failures\n    await new Promise(r => setTimeout(r, 5000));\n    return runRushInstall();\n  } else throw e;\n}","preventionTips":["Provide registry auth tokens via .npmrc/env (NPM_TOKEN) in CI","Retry transient network failures with backoff","Pin exact package versions to reduce registry lookups","Verify registry/proxy config with a manual `npm view` preflight"],"tags":["npm","registry","network"],"backgroundTag":"npm-registry-lookup-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}