{"record":{"id":"141b481dc62e5a41","repo":"remix-run/react-router","slug":"prerender-resource-received-a-response-status","errorCode":null,"errorMessage":"Prerender (resource): Received a ${response.status} status code from `entry.server.tsx` while prerendering the `${pathname}` path.\n${new TextDecoder().decode(contents)}","messagePattern":"Prerender \\(resource\\): Received a (.+?) status code from `entry\\.server\\.tsx` while prerendering the `(.+?)` path\\.\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/vite/plugin.ts","lineNumber":2585,"sourceCode":"                path: pathname,\n                contents: data,\n              },\n            ],\n            // After saving the .data file, request the HTML page.\n            // The data is passed along to be embedded in the response header.\n            requests: !metadata.isResourceRoute\n              ? [createRouteRequest(metadata.path, ctx.reactRouterConfig, data)]\n              : [],\n          };\n        }\n\n        // Handle resource route responses\n        if (metadata.type === \"resource\") {\n          let pathname = new URL(request.url).pathname;\n          let contents = new Uint8Array(await response.arrayBuffer());\n\n          if (response.status !== 200) {\n            throw new Error(\n              `Prerender (resource): Received a ${response.status} status code from ` +\n                `\\`entry.server.tsx\\` while prerendering the \\`${pathname}\\` ` +\n                `path.\\n${new TextDecoder().decode(contents)}`,\n            );\n          }\n\n          return [\n            {\n              path: pathname,\n              contents,\n            },\n          ];\n        }\n\n        // Handle document responses (html or spa)\n        let html = await response.text();\n\n        if (metadata.type === \"spa\") {","sourceCodeStart":2567,"sourceCodeEnd":2603,"githubUrl":"https://github.com/remix-run/react-router/blob/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/react-router-dev/vite/plugin.ts#L2567-L2603","documentation":"When prerendering a resource route (a route with no default export, like `routes/robots[.]txt.ts`), React Router requests it from the built server and requires a 200 response. Any other status means the resource route handler failed while generating static output. The error message embeds the decoded response body so you can see the server-side error text.","triggerScenarios":"A resource route listed in `prerender` whose handler throws (e.g. external fetch failure during build); a resource route returning `json(..., { status: 500 })`; a resource route relying on runtime-only context (env vars, request cookies) that is absent during the build-time request.","commonSituations":"Prerendering `robots.txt`, `sitemap.xml`, or RSS feeds whose handlers call slow or rate-limited third-party APIs; resource routes reading `process.env` keys that exist in deploy but not in CI; handlers that redirect (3xx) which are not valid static files.","solutions":["Run the resource route handler directly (or hit the dev server URL) to reproduce the failure and fix the thrown error","Make build-time dependencies resilient: guard the external call, cache the result, or commit static content and serve it directly instead of prerendering","Ensure required environment variables are set in the build/CI environment, not only at runtime","Drop the resource route from the `prerender` list and generate the file with a script if it cannot succeed at build time"],"exampleFix":"// before (app/routes/sitemap[.]xml.ts)\nexport async function loader() {\n  let res = await fetch('https://api.example.com/pages');\n  if (!res.ok) throw new Response('upstream failed', { status: 502 });\n  return new Response(await res.text());\n}\n\n// after — degrade gracefully at build time\nexport async function loader() {\n  let res = await fetch('https://api.example.com/pages');\n  if (!res.ok) {\n    return new Response('<?xml version=\"1.0\"?><urlset></urlset>', {\n      headers: { 'Content-Type': 'application/xml' },\n    });\n  }\n  return new Response(await res.text());\n}","handlingStrategy":"validation","validationCode":"// Dry-run a resource route before prerendering it\nconst res = await fetch(`http://localhost:3000/robots.txt`);\nif (!res.ok) {\n  throw new Error(`Refusing to prerender /robots.txt — dev server returned ${res.status}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (e instanceof Error && /^Prerender \\(resource\\)/.test(e.message)) {\n    // message already embeds the decoded response body — surface it in CI logs\n    console.error(e.message);\n  }\n}","preventionTips":["Keep resource-route handlers free of uncached external calls","Provide build-time fallbacks or committed static files for feeds/sitemaps","Test resource routes in CI against a locally served build before enabling prerender"],"tags":["prerender","ssg","resource-route","build"],"backgroundTag":"prerender-response-error","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}