{"record":{"id":"c2f4944ae7cc974b","repo":"vercel/next.js","slug":"request-failed-with-empty-body","errorCode":null,"errorMessage":"request failed with empty body","messagePattern":"request failed with empty body","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/lib/download-swc.ts","lineNumber":51,"sourceCode":"      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            )\n          },\n          close() {\n            return new Promise<void>((resolve, reject) =>","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/download-swc.ts#L33-L69","documentation":"Thrown by download-swc.ts when the registry responded OK (2xx) but the response body stream is null/absent. Even though the status looked successful, there is no content to pipe to disk, so Next.js refuses to write an empty/corrupt tarball and aborts the SWC extraction.","triggerScenarios":"extractBinary() fetches the SWC tarball, res.ok is true but res.body is falsy. Happens with misbehaving proxies/CDNs that return 200 with no body, registries streaming errors inside a 200 envelope, or HTTP/2 intermediaries that drop the stream.","commonSituations":"Corporate proxies (Artifactory, Squid, Zscaler) that return 200 for HEAD-like requests or strip the body; a registry mirror that 200-redirects to a broken upstream; or a flaky CDN edge serving an empty response. Distinguished from [107] by the OK status.","solutions":["Retry the build (transient empty-body responses often clear on retry) — but change something (clean .next, retry once) per retry discipline.","Point npm to a healthier registry mirror or bypass the corporate proxy for registry.npmjs.org.","Pre-install the @next/swc-<triple> package so the on-demand download path is never exercised.","Verify the proxy/CDN configuration preserves response bodies for binary package tarballs."],"exampleFix":"# before\npnpm build  # 200 but empty body -> error\n# after: pre-install so no fetch happens\npnpm add @next/swc-linux-x64-gnu\npnpm build","handlingStrategy":"retry","validationCode":"// Verify the registry returns a non-empty body for the tarball HEAD\nasync function swcTarballHasBody(url: string): Promise<boolean> {\n  const r = await fetch(url)\n  return r.ok && Boolean(r.body)\n}","typeGuard":null,"tryCatchPattern":"async function downloadBody(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 (!r.ok) throw new Error(`status ${r.status}`)\n    if (i === attempts - 1) throw new Error('request failed with empty body')\n  }\n  throw new Error('unreachable')\n}","preventionTips":["Pre-install the SWC binary to bypass the download path entirely.","If behind a corporate proxy, validate it preserves binary response bodies.","Retry once with a fresh .next cache; report persistent empty bodies to the registry operator.","Prefer a registry mirror known to serve complete tarballs."],"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"}