{"record":{"id":"04908e4c18132e33","repo":"sveltejs/kit","slug":"cannot-prerender-a-route-with-both-page-and-serv","errorCode":null,"errorMessage":"Cannot prerender a route with both +page and +server files (${route.id})","messagePattern":"Cannot prerender a route with both \\+page and \\+server files \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/core/postbuild/analyse.js","lineNumber":102,"sourceCode":"\t\tmetadata.nodes[node.index] = {\n\t\t\thas_server_load: has_server_load(node),\n\t\t\thas_universal_load: node.universal?.load !== undefined\n\t\t};\n\t}\n\n\t// analyse routes\n\tfor (const route of manifest.routes) {\n\t\tconst page =\n\t\t\troute.page &&\n\t\t\tanalyse_page(\n\t\t\t\troute.page.layouts.map((n) => (n === undefined ? n : nodes[n])),\n\t\t\t\tnodes[route.page.leaf]\n\t\t\t);\n\n\t\tconst endpoint = route.endpoint && analyse_endpoint(route, await route.endpoint());\n\n\t\tif (page?.prerender && endpoint?.prerender) {\n\t\t\tthrow new Error(`Cannot prerender a route with both +page and +server files (${route.id})`);\n\t\t}\n\n\t\tif (page?.config && endpoint?.config) {\n\t\t\tfor (const key in { ...page.config, ...endpoint.config }) {\n\t\t\t\tif (JSON.stringify(page.config[key]) !== JSON.stringify(endpoint.config[key])) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Mismatched route config for ${route.id} — the +page and +server files must export the same config, if any`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst route_config = page?.config ?? endpoint?.config ?? {};\n\t\tconst prerender = page?.prerender ?? endpoint?.prerender;\n\n\t\tif (prerender !== true) {\n\t\t\tfor (const feature of list_features(\n\t\t\t\troute,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/core/postbuild/analyse.js#L84-L120","documentation":"A route directory containing both +page and +server files can export `prerender` from each; if both sides declare prerender truthy, SvelteKit cannot decide how to prerender the route (page vs endpoint) and throws at analysis time after build.","triggerScenarios":"A directory like src/routes/api/thing has both +page.js/+page.svelte and +server.js, and both export `export const prerender = true` (or inherit truthy prerender from a parent layout/kit config combined with a local one).","commonSituations":"Converting a prerendered page into an API endpoint by adding +server.js without removing the page's prerender export; a layout-wide `export const prerender = true` plus endpoint prerender.","solutions":["Remove `export const prerender = true` from one of the two files — usually keep it on +page.js and let +server.js not declare it, or split the route into separate directories.","If both page data and an endpoint are needed, move the +server.js into a different route path.","Check parent +layout.js files for a blanket prerender export affecting the endpoint."],"exampleFix":"// before (+server.js in a route that also has +page.js with prerender = true)\nexport const prerender = true;\nexport const GET = () => new Response('ok');\n// after\nexport const GET = () => new Response('ok');","handlingStrategy":"validation","validationCode":"// ensure only the +page side declares prerender in mixed routes\nconst pageSrc = await fs.readFile('src/routes/demo/+page.js', 'utf8');\nconst serverSrc = await fs.readFile('src/routes/demo/+server.js', 'utf8');\nconst both = /export\\s+const\\s+prerender\\s*=\\s*true/.test(pageSrc) &&\n             /export\\s+const\\s+prerender\\s*=\\s*true/.test(serverSrc);\nif (both) throw new Error('Both +page and +server declare prerender = true');","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (String(e.message).includes('both +page and +server')) {\n    console.error('Remove the prerender export from one of the files in:', e.message);\n  } else throw e;\n}","preventionTips":["When adding +server.js to a prerendered page route, strip the prerender export from one side.","Check parent layouts for blanket `export const prerender = true` before adding endpoints.","Split page and API concerns into separate route directories when possible."],"tags":["prerender","routing","build"],"backgroundTag":"conflicting-prerender-exports","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}