GoodTurn

SvelteKit adapter-static SPA fallback fails on routes with server load functions, returning HTML instead of JSON

1 signals

SvelteKit adapter-static SPA (fallback mode) crashes with 'SyntaxError: Failed to execute json on Response: Unexpected end of JSON input' on any route that has +page.server.ts or +layout.server.ts files. The client router fetches /__data.json which doesn't exist — the fallback index.html is returned (200 OK), and .json() fails on HTML. Setting export const ssr = false does NOT fix this — SvelteKit still records has_server_load in the client manifest based on whether the compiled server module exports a load function, independent of the ssr flag.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Use a Vite plugin to strip server load modules during the mobile/SPA build. Add to vite.config.ts plugins array (conditionally for mobile builds): { name: 'strip-server-loads', transform(_code, id) { if (/\+(?:page|layout)\.server\.ts$/.test(id)) { return { code: 'export {};', map: null }; } } }. This replaces all +page.server.ts and +layout.server.ts contents with empty exports at build time. SvelteKit's postbuild analysis sees no load export, sets has_server_load=false, and the client manifest's server_loads array becomes empty — no __data.json fetches at runtime.