vercel/next.js · error · Error
request failed with empty body
Error message
request failed with empty body
What it means
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.
Source
Thrown at packages/next/src/lib/download-swc.ts:51
cacheDirectory,
`${tarFileName}.temp-${Date.now()}`
)
const registry = getRegistry()
const downloadUrl = `${registry}${pkgName}/-/${tarFileName}`
await fetch(downloadUrl).then((res) => {
const { ok, body } = res
if (!ok || !body) {
Log.error(`Failed to download swc package from ${downloadUrl}`)
}
if (!ok) {
throw new Error(`request failed with status ${res.status}`)
}
if (!body) {
throw new Error('request failed with empty body')
}
const cacheWriteStream = fs.createWriteStream(tempFile)
return body.pipeTo(
new WritableStream({
write(chunk) {
return new Promise<void>((resolve, reject) =>
cacheWriteStream.write(chunk, (error) => {
if (error) {
reject(error)
return
}
resolve()
})
)
},
close() {
return new Promise<void>((resolve, reject) =>View on GitHub (pinned to 0ae8c72462)
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.
Example fix
# before pnpm build # 200 but empty body -> error # after: pre-install so no fetch happens pnpm add @next/swc-linux-x64-gnu pnpm build
Defensive patterns
Strategy: retry
Validate before calling
// Verify the registry returns a non-empty body for the tarball HEAD
async function swcTarballHasBody(url: string): Promise<boolean> {
const r = await fetch(url)
return r.ok && Boolean(r.body)
} Try / catch
async function downloadBody(url: string, attempts = 3) {
for (let i = 0; i < attempts; i++) {
const r = await fetch(url)
if (r.ok && r.body) return r
if (!r.ok) throw new Error(`status ${r.status}`)
if (i === attempts - 1) throw new Error('request failed with empty body')
}
throw new Error('unreachable')
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- request failed with status ${res.status}
- Failed to get registry from "${pkgManager}".
- Failed to fetch ${url}
- Command failed: ${command} ${args.join(' ')} (exit ${code})
- Missing ${NEXT_BIN}. Build Next.js first (pnpm --filter=next
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/c2f4944ae7cc974b.
Report an issue: GitHub.