{"record":{"id":"64f8ece20f44671c","repo":"withastro/astro","slug":"the-prerender-server-responded-response-status","errorCode":null,"errorMessage":"the prerender server responded ${response.status} ${response.statusText}${details}","messagePattern":"the prerender server responded (.+?) (.+?)(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/cloudflare/src/prerenderer.ts","lineNumber":149,"sourceCode":"\tsourcePath: string | undefined,\n): Promise<void> {\n\tconst response = await fetch(createImageTransformUrl(serverUrl, originalPath, transform), {\n\t\tmethod: 'POST',\n\t\t// Remote images have no local original; the worker fetches those itself.\n\t\t...(sourcePath\n\t\t\t? {\n\t\t\t\t\tbody: Readable.toWeb(createReadStream(sourcePath)) as unknown as BodyInit,\n\t\t\t\t\t// Required by Node's fetch whenever the body is a stream.\n\t\t\t\t\tduplex: 'half',\n\t\t\t\t}\n\t\t\t: {}),\n\t} as RequestInit);\n\n\tif (!response.ok || !response.body) {\n\t\t// The body can be a full error page, so keep only enough of it to be useful.\n\t\tconst body = (await response.text().catch(() => '')).replace(/\\s+/g, ' ').trim();\n\t\tconst details = body ? `: ${body.slice(0, 200)}` : '';\n\t\tthrow new Error(\n\t\t\t`the prerender server responded ${response.status} ${response.statusText}${details}`,\n\t\t);\n\t}\n\n\tconst outputPath = join(fileURLToPath(clientDir), finalPath);\n\tawait mkdir(dirname(outputPath), { recursive: true });\n\t// `fetch` types the body as the DOM `ReadableStream`, which is structurally\n\t// identical to but nominally distinct from the `node:stream/web` one.\n\tconst body = response.body as unknown as NodeReadableStream<Uint8Array>;\n\tawait pipeline(Readable.fromWeb(body), createWriteStream(outputPath));\n}\n\n/**\n * Creates a prerenderer that uses Cloudflare's workerd runtime via a preview server.\n * This allows prerendering to happen in the same runtime that will serve the pages.\n */\nexport function createCloudflarePrerenderer({\n\troot,","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/cloudflare/src/prerenderer.ts#L131-L167","documentation":"Thrown by the Cloudflare prerenderer when the internal prerender HTTP server (a local `workerd` instance fronted by a Vite preview server) returns a non-OK response or an empty body for a page request. The error includes the HTTP status, status text, and a trimmed slice of the response body (first 200 chars) to aid diagnosis. This is the fetch call that renders a single route to capture its HTML.","triggerScenarios":"During `astro build` with the Cloudflare adapter in prerender mode, the per-route fetch to the local workerd server returns 4xx/5xx. Causes include an unhandled exception in the page's workerd handler, a missing binding, or workerd crashing. The guard is `!response.ok || !response.body`.","commonSituations":"A page throws during SSR inside workerd (e.g. referencing an undefined env binding). Missing or misnamed Cloudflare bindings (KV, D1, R2, vars). workerd runtime incompatibility with a dependency. Port conflicts on the ephemeral preview server.","solutions":["Inspect the trimmed body in the error message — it often contains the workerd stack trace or binding error.","Verify all bindings declared in `wrangler.toml`/`wrangler.jsonc` are present and correctly named for local dev.","Run `astro dev` with the adapter to reproduce the page error with full HMR output before retrying the build.","Check workerd is installed and the version matches what @astrojs/cloudflare expects."],"exampleFix":"// before — binding used but not declared\nexport const GET = ({ locals }) => Response.json(locals.cfContext.env.MY_KV);\n\n// after — declare binding in wrangler config\n// wrangler.jsonc: { \"kv_namespaces\": [{ \"binding\": \"MY_KV\", \"id\": \"...\" }] }","handlingStrategy":"try-catch","validationCode":"// Before build, smoke-test that all pages render in `astro dev` with the adapter,\n// and that every referenced binding is declared in wrangler config.","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (/prerender server responded/.test(e.message)) {\n    // e.message contains status + trimmed body: inspect for binding/runtime errors\n    console.error('Prerender failure:', e.message);\n  }\n  throw e;\n}","preventionTips":["Declare every binding your pages use in wrangler.toml/wrangler.jsonc.","Run astro dev with the adapter to catch page errors before build.","Keep workerd and @astrojs/cloudflare versions in sync."],"tags":["cloudflare","prerender","workerd","build","network"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}