sveltejs/kit · error

Cannot prerender a route with both +page and +server files (

Error message

Cannot prerender a route with both +page and +server files (${route.id})

What it means

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.

Source

Thrown at packages/kit/src/core/postbuild/analyse.js:102

		metadata.nodes[node.index] = {
			has_server_load: has_server_load(node),
			has_universal_load: node.universal?.load !== undefined
		};
	}

	// analyse routes
	for (const route of manifest.routes) {
		const page =
			route.page &&
			analyse_page(
				route.page.layouts.map((n) => (n === undefined ? n : nodes[n])),
				nodes[route.page.leaf]
			);

		const endpoint = route.endpoint && analyse_endpoint(route, await route.endpoint());

		if (page?.prerender && endpoint?.prerender) {
			throw new Error(`Cannot prerender a route with both +page and +server files (${route.id})`);
		}

		if (page?.config && endpoint?.config) {
			for (const key in { ...page.config, ...endpoint.config }) {
				if (JSON.stringify(page.config[key]) !== JSON.stringify(endpoint.config[key])) {
					throw new Error(
						`Mismatched route config for ${route.id} — the +page and +server files must export the same config, if any`
					);
				}
			}
		}

		const route_config = page?.config ?? endpoint?.config ?? {};
		const prerender = page?.prerender ?? endpoint?.prerender;

		if (prerender !== true) {
			for (const feature of list_features(
				route,

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. 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.
  2. If both page data and an endpoint are needed, move the +server.js into a different route path.
  3. Check parent +layout.js files for a blanket prerender export affecting the endpoint.

Example fix

// before (+server.js in a route that also has +page.js with prerender = true)
export const prerender = true;
export const GET = () => new Response('ok');
// after
export const GET = () => new Response('ok');
Defensive patterns

Strategy: validation

Validate before calling

// ensure only the +page side declares prerender in mixed routes
const pageSrc = await fs.readFile('src/routes/demo/+page.js', 'utf8');
const serverSrc = await fs.readFile('src/routes/demo/+server.js', 'utf8');
const both = /export\s+const\s+prerender\s*=\s*true/.test(pageSrc) &&
             /export\s+const\s+prerender\s*=\s*true/.test(serverSrc);
if (both) throw new Error('Both +page and +server declare prerender = true');

Try / catch

try {
  await build();
} catch (e) {
  if (String(e.message).includes('both +page and +server')) {
    console.error('Remove the prerender export from one of the files in:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/04908e4c18132e33. Report an issue: GitHub.