{"record":{"id":"7f49369a64f8e413","repo":"hcengineering/platform","slug":"npm-view-returned-error-code-npmversionspawnre-7f4936","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/utils/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/utils/common/scripts/install-run.js#L487-L523","documentation":"_resolvePackageVersion runs `npm view <name>@<version> version --json` to resolve a version range to the latest satisfying version. A non-zero exit status from that spawned npm process throws this error with the exit code. It indicates npm itself failed to query the registry, not that parsing failed.","triggerScenarios":"spawnSync of the platform npm path with ['view', `${name}@${version}`, 'version', ...] returns status !== 0, e.g. package/version range not found, no network to the registry, registry authentication required, or npm crashes.","commonSituations":"Offline CI or blocked registry host (corporate proxy/firewall); typo in the package name or an impossible version range; private registry package requiring credentials (NPM_TOKEN missing); registry outage.","solutions":["Verify network access to the configured registry: `npm view <package> version` manually with the same npm","Check the package name and version range for typos or a range matching no published version","Configure registry credentials (NPM_TOKEN / .npmrc) if the package is private","Check registry status (npmjs.com status page) and retry if it is an outage"],"exampleFix":"// before: private package, no auth in CI\nnpm view @myorg/private-pkg@^1.0.0 version  ->  E404\n// after\nenv:\n  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}\n# plus .npmrc: //registry.npmjs.org/:_authToken=${NPM_TOKEN}","handlingStrategy":"retry","validationCode":"const { execSync } = require('child_process');\nfunction assertRegistryReachable(name) {\n  execSync(`npm view ${name} version --no-update-notifier`, { stdio: 'inherit' });\n}\nassertRegistryReachable('pnpm'); // fails fast with npm's own diagnostics","typeGuard":null,"tryCatchPattern":"try {\n  installAndRun(logger, packageDir, name, version, command);\n} catch (e) {\n  if (/\"npm view\" returned error code/.test(e.message)) {\n    // transient registry/network issue: retry with backoff\n  }\n  throw e;\n}","preventionTips":["Configure registry auth (.npmrc + NPM_TOKEN) for private packages before running","Set HTTP(S)_PROXY in restricted networks","Pin versions that are known to exist on the registry"],"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"}