sveltejs/kit · error · Error
Could not create a fallback page
Error message
Could not create a fallback page
What it means
With adapter-static's `fallback` option, SvelteKit builds a SPA fallback page by booting the built server in a subprocess and requesting the synthetic route /[fallback]. If the response is not ok, generate_fallback throws this stackless error. Typical causes are server-side errors during the fallback render (load failures, missing routes, bad env).
Source
Thrown at packages/kit/src/core/postbuild/fallback.js:52
const response = await server.respond(new Request(origin + '/[fallback]'), {
getClientAddress: () => {
throw new Error('Cannot read clientAddress during prerendering');
},
prerendering: {
fallback: true,
dependencies: new Map(),
remote_responses: new Map(),
resolved_route_ids: new Set()
},
read: (file) => readFileSync(join(assets, file))
});
if (response.ok) {
return await response.text();
}
throw stackless('Could not create a fallback page');
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Look for the server error logged before this message (the fallback render usually prints the real 500 cause)
- Ensure load functions tolerate the synthetic /[fallback] route and don't throw (guard on route.id or use fallback-safe code)
- Pass the required env variables to the build so server.init({ env }) succeeds
- Set `strict: false` / provide `fallback: 'index.html'`-style static fallback instead of dynamic generation if the app is purely client-rendered
Example fix
// before (+layout.server.js)
export async function load({ params }) {
return { page: await getPage(params.slug) }; // throws for /undefined-slug fallback
}
// after
export async function load({ params }) {
const page = await getPage(params.slug).catch(() => null);
return { page };
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify the fallback route renders before full build
const res = await server.respond(new Request(origin + '/[fallback]'), { prerendering: { fallback: true } });
if (!res.ok) throw new Error(`fallback render returned ${res.status}`); Try / catch
try {
const html = await generateFallback(opts);
} catch (e) {
console.error('Fallback generation failed; check server error above');
throw e;
} Prevention
- Make load functions resilient for the synthetic /[fallback] route
- Provide required env vars at build time
- Verify adapter-static fallback config and origin settings
- Log and handle errors in the root layout load
When it happens
Trigger: Running `vite build` with adapter-static fallback configured and the internal server.respond for origin + '/[fallback]' returns a non-ok status (e.g. 500 from a load function throwing, missing prerendered dependencies, invalid manifest/env).
Common situations: +layout.server.js or root load throws for the fallback route; env vars required by load functions absent at build time; adapter-static fallback set but app has server-only endpoints erroring; misconfigured origin or assets paths.
Related errors
- Page options are ignored when `router.type === 'hash'` (${no
- Cannot prerender a route with both +page and +server files (
- Cannot prerender a +server file with ${BODY_DEPENDENT_METHOD
- Cannot read clientAddress during prerendering
- Cannot prerender a root +server.js that returns a non-HTML r
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/49cb4626e162a461.
Report an issue: GitHub.