{"record":{"id":"088b2644b4be9bcd","repo":"withastro/astro","slug":"failed-to-get-static-paths-from-the-cloudflare-pre","errorCode":null,"errorMessage":"Failed to get static paths from the Cloudflare prerender server (${response.status}: ${response.statusText}).${details}","messagePattern":"Failed to get static paths from the Cloudflare prerender server \\((.+?): (.+?)\\)\\.(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/cloudflare/src/prerenderer.ts","lineNumber":242,"sourceCode":"\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Failed to start the Cloudflare prerender server. The preview server did not return a valid address. ' +\n\t\t\t\t\t\t'This is likely a bug in @astrojs/cloudflare. Please file an issue at https://github.com/withastro/astro/issues',\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\tasync getStaticPaths(): Promise<PathWithRoute[]> {\n\t\t\t// Call the workerd endpoint to get static paths\n\t\t\tconst response = await fetch(`${serverUrl}${STATIC_PATHS_ENDPOINT}`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst body = await response.text();\n\t\t\t\tconst details = body ? `\\n${body}` : '';\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to get static paths from the Cloudflare prerender server (${response.status}: ${response.statusText}).${details}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst data: StaticPathsResponse = await response.json();\n\n\t\t\t// Deserialize the routes\n\t\t\treturn data.paths.map(({ pathname, route, cacheKey }) => ({\n\t\t\t\tpathname,\n\t\t\t\troute: deserializeRouteData(route),\n\t\t\t\tcacheKey,\n\t\t\t}));\n\t\t},\n\n\t\tasync render(request, { routeData }) {\n\t\t\t// Serialize routeData and send to workerd\n\t\t\tconst body: PrerenderRequest = {\n\t\t\t\turl: request.url,","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/cloudflare/src/prerenderer.ts#L224-L260","documentation":"Thrown by the Cloudflare prerenderer when fetching the list of static paths from the local workerd server fails (non-OK response). The `getStaticPaths` method POSTs to the `STATIC_PATHS_ENDPOINT` on the prerender server to discover which routes need prerendering; a failure here means workerd could not enumerate routes.","triggerScenarios":"During build, the POST to `${serverUrl}${STATIC_PATHS_ENDPOINT}` returns non-2xx. The response body (if any) is appended as `details`. Commonly caused by an exception during route enumeration in workerd, a missing getStaticPaths export, or the workerd handler crashing on import.","commonSituations":"A dynamic route's `getStaticPaths` throws inside workerd. An imported module at the top level of a page fails under workerd (e.g. Node-only API). Bindings missing during the static-paths phase. workerd import resolution differences from Node.","solutions":["Read the `details` body in the error — it carries workerd's error output.","Audit dynamic routes' `getStaticPaths` for code that runs at the top level or uses Node-only APIs.","Ensure all page modules import cleanly under workerd (no `fs`, `child_process`, etc. at module scope).","Run `astro dev` with the adapter to surface the page-level error with a full stack trace."],"exampleFix":"// before — Node-only API at module scope\nimport { readFileSync } from 'node:fs';\nconst data = readFileSync('./data.json');\nexport const GET = () => new Response(data);\n\n// after — read at build time or use a binding\nexport const GET = async ({ locals }) => {\n  const data = await locals.cfContext.env.MY_BUCKET.get('data.json');\n  return new Response(data);\n};","handlingStrategy":"try-catch","validationCode":"// Ensure no page module uses Node-only APIs at module scope.\n// Audit: grep -rn \"from 'node:\" in src/pages and src/components used by pages.","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (/Failed to get static paths/.test(e.message)) {\n    // details body contains workerd's error; inspect dynamic routes' getStaticPaths\n  }\n  throw e;\n}","preventionTips":["Keep getStaticPaths pure — no Node-only APIs, no top-level side effects.","Ensure all page imports resolve under workerd (no node:fs, node:child_process at scope).","Test dynamic routes in astro dev with the adapter before building."],"tags":["cloudflare","prerender","workerd","build","static-paths"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}