sveltejs/kit · error · Error

Cannot prerender pages with actions

Error message

Cannot prerender pages with actions

What it means

Prerendering executes pages at build time with no ability to mutate server state, so a page whose `+page.server.js` exports `actions` cannot be prerendered. `render_page` throws when `export const prerender = true` coexists with server `actions`.

Source

Thrown at packages/kit/src/runtime/server/page/index.js:89

			if (action_result?.type === 'redirect') {
				return redirect_response(action_result.status, action_result.location);
			}
			if (action_result?.type === 'error') {
				status = get_status(action_result.error);
			}
			if (action_result?.type === 'failure') {
				status = action_result.status;
			}
		}

		// it's crucial that we do this before returning the non-SSR response, otherwise
		// SvelteKit will erroneously believe that the path has been prerendered,
		// causing functions to be omitted from the manifest generated later
		const should_prerender = nodes.prerender();
		if (should_prerender) {
			const mod = leaf_node.server;
			if (mod?.actions) {
				throw new Error('Cannot prerender pages with actions');
			}
		} else if (state.prerendering) {
			// if the page isn't marked as prerenderable, then bail out at this point
			return new Response(undefined, {
				status: 204
			});
		}

		// if we fetch any endpoints while loading data for this page, they should
		// inherit the prerender option of the page
		state.prerender_default = should_prerender;

		const should_prerender_data = nodes.should_prerender_data();
		const data_pathname = add_data_suffix(event.url.pathname);

		/** @type {import('./types.js').Fetched[]} */
		const fetched = [];

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove `actions` from the page's `+page.server.js` (use a `+server.js` POST endpoint or client-side handling instead)
  2. Set `export const prerender = false` for that page (e.g. via `+page.js`) to exclude it from prerendering
  3. If prerendering globally, scope `prerender = true` to routes without actions

Example fix

// +page.js (before)
export const prerender = true;
// after
export const prerender = false; // page has server actions
Defensive patterns

Strategy: validation

Validate before calling

// +page.js
export const prerender = !import.meta.env.SSR ? true : typeof pageActions === 'undefined';

Prevention

When it happens

Trigger: Setting `export const prerender = true` in `+page.js`/`+layout.js` (or enabling prerender globally in svelte.config.js) on a route that also has `export const actions` in `+page.server.js`.

Common situations: Turning on `prerender = true` in the root layout and later adding a login/contact form to a page; copy-pasting a prerender config into a form page; `export const prerender = 'auto'` resolving to true for an action page.

Related errors


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