{"record":{"id":"d72c7d4c3861eb06","repo":"vercel/next.js","slug":"request-failed-with-status-res-status","errorCode":null,"errorMessage":"request failed with status ${res.status}","messagePattern":"request failed with status (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/lib/download-swc.ts","lineNumber":48,"sourceCode":"    Log.info(`Downloading swc package ${pkgName}... to ${cacheDirectory}`)\n    await fs.promises.mkdir(cacheDirectory, { recursive: true })\n    const tempFile = path.join(\n      cacheDirectory,\n      `${tarFileName}.temp-${Date.now()}`\n    )\n\n    const registry = getRegistry()\n\n    const downloadUrl = `${registry}${pkgName}/-/${tarFileName}`\n\n    await fetch(downloadUrl).then((res) => {\n      const { ok, body } = res\n      if (!ok || !body) {\n        Log.error(`Failed to download swc package from ${downloadUrl}`)\n      }\n\n      if (!ok) {\n        throw new Error(`request failed with status ${res.status}`)\n      }\n      if (!body) {\n        throw new Error('request failed with empty body')\n      }\n      const cacheWriteStream = fs.createWriteStream(tempFile)\n      return body.pipeTo(\n        new WritableStream({\n          write(chunk) {\n            return new Promise<void>((resolve, reject) =>\n              cacheWriteStream.write(chunk, (error) => {\n                if (error) {\n                  reject(error)\n                  return\n                }\n\n                resolve()\n              })\n            )","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/download-swc.ts#L30-L66","documentation":"Thrown by download-swc.ts when the HTTP fetch for a platform-specific SWC native binary (@next/swc-<triple>) returns a non-OK status from the package registry. Next.js downloads the SWC binary on demand when the bundled native binding is missing; a failing registry response (4xx/5xx) aborts extraction so a corrupt/empty binary is never installed.","triggerScenarios":"Occurs during dev/build when the native .node binding is absent and extractBinary() fetches the tarball. res.ok is false — the registry returned an error status (404 for unknown triple, 401/403 for private registry auth, 5xx for outage, 451 for blocked region).","commonSituations":"Custom npm registry (Verdaccio, Artifactory, Nexus) that lacks the @next/swc-* package; offline or corporate-proxy environments blocking registry.npmjs.org; a typo'd platform triple; npmrc auth misconfiguration; or a transient npm registry outage. Also seen when a private registry mirrors only some scopes.","solutions":["Check network/registry reachability: `npm ping` and verify the @next/swc-<triple> package exists on your configured registry.","Ensure .npmrc auth tokens are set for private registries and that the registry proxies the full @next scope including @next/swc-*.","Pre-install the matching SWC binary manually: `npm install @next/swc-<os>-<arch>-<libc>` so download is skipped.","If offline, copy the SWC binary from another machine into packages/next-swc/native/ or set NEXT_SWC_PATH to a cached tarball."],"exampleFix":"# before: missing binary, registry returns 404\npnpm build\n# after: install the platform binary explicitly\npnpm add @next/swc-linux-x64-gnu\npnpm build","handlingStrategy":"retry","validationCode":"// Pre-flight: confirm the SWC package is reachable on the registry\nasync function swcBinaryReachable(triple: string, version: string): Promise<boolean> {\n  const r = await fetch(`https://registry.npmjs.org/@next/swc-${triple}/${version}`)\n  return r.ok\n}","typeGuard":null,"tryCatchPattern":"async function downloadWithRetry(url: string, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    const r = await fetch(url)\n    if (r.ok && r.body) return r\n    if (i === attempts - 1) throw new Error(`request failed with status ${r.status}`)\n    await new Promise((res) => setTimeout(res, 500 * (i + 1)))\n  }\n  throw new Error('unreachable')\n}","preventionTips":["Pre-install the @next/swc-<triple> package to skip the on-demand download.","Ensure .npmrc auth and registry config cover the @next scope in restricted networks.","Add a pre-build registry reachability check in CI.","Keep a cached tarball (NEXT_SWC_PATH) for offline builds."],"tags":["network","swc","build","registry","native-binary"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}