{"record":{"id":"3d8a10f8bb02935a","repo":"hcengineering/platform","slug":"npm-view-returned-error-code-npmversionspawnre","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/communication/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/communication/common/scripts/install-run.js#L487-L523","documentation":"_resolvePackageVersion shells out to `npm view <name>@<version-range> version --json` to resolve a version range to the latest satisfying version. A nonzero exit status from that spawnSync throws this error with the status code. It means npm itself failed to query the registry.","triggerScenarios":"`npm view` exits nonzero because the package or version range does not exist, the registry is unreachable, npm is misconfigured (bad registry URL, auth required for a private package), or network is down.","commonSituations":"Typo in package name; private scoped package without registry auth token; corporate proxy/firewall blocking registry.npmjs.org; npm registry outage; specifying a version range that matches nothing.","solutions":["Run `npm view <name>@<version> version` manually to see the underlying npm error.","Verify network/proxy access to the npm registry (npm config get proxy, registry URL).","If it's a private package, configure the .npmrc auth token for its scope.","Check that the package name and version range are correct and exist in the registry."],"exampleFix":"// before (no auth for private scope)\nnode install-run.js @mycorp/cli@1.2.0 -- some-cmd\n// after: add registry auth first\nnpm config set @mycorp:registry https://npm.mycorp.com\nnpm login --scope=@mycorp\nnode install-run.js @mycorp/cli@1.2.0 -- some-cmd","handlingStrategy":"retry","validationCode":"const name = 'pnpm'; // verify before invoking install-run\nrequire('child_process').execSync(`npm view ${name}@8 version`, { stdio: 'inherit' });","typeGuard":null,"tryCatchPattern":"try { runInstall(); } catch (e) { if (/\"npm view\" returned error code/.test(e.message)) { await new Promise(r => setTimeout(r, 5000)); /* retry up to 3x for transient registry/network issues */ } else throw e; }","preventionTips":["Configure .npmrc registry/proxy/auth before running in CI","Pre-warm with `npm view pkg@range version` to fail early with a clear message","Use a resilient registry mirror (e.g. npm proxy) behind corporate firewalls"],"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"}