adapter-static has issues with server endpoints
See original GitHub issueDescribe the bug
One last issue on my big SvelteKit 350 to 551 upgrade… I’m using adapter-static to spit out some HTML files and serving those statically, some of those are even dynamic routes and that works fine with export const prerender = true.
The issue I’m having though is, I have a backend proxy I only use in development mode. You can see it added to my repro case in this commit: https://github.com/johnnysprinkles/sveltekit_static_dynamic/commit/e91dbdf61d410d817988b06c890513c76bbd6376 In that example it returns a simple string, but in real life is make an HTTP fetch to my actual backend.
With that in place, “npm run build” ends up failing with this message:
> Using @sveltejs/adapter-static
@sveltejs/adapter-static: all routes must be fully prerenderable (unless using the 'fallback' option — see https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode). Try adding `export const prerender = true` to your root +layout.js/.ts file — see https://kit.svelte.dev/docs/page-options#prerender for more details
- src/routes/api/[...rest]
error during build:
Error: Encountered dynamic routes
at adapt (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/@sveltejs/adapter-static/index.js:35:12)
at adapt (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:8)
at Object.handler (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/@sveltejs/kit/src/exports/vite/index.js:488:12)
at async PluginDriver.hookParallel (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/rollup/dist/es/shared/rollup.js:22632:17)
at async Object.close (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/rollup/dist/es/shared/rollup.js:23709:13)
at async Promise.all (index 0)
at async build (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/vite/dist/node/chunks/dep-db16f19c.js:45667:13)
at async CAC.<anonymous> (file:///Users/jpsimons/dev/sveltekit_static_dynamic/node_modules/vite/dist/node/cli.js:748:9)
Is there a way to make the “dynamic route” check logic ignore server endpoints?
Reproduction
The repro is in https://github.com/johnnysprinkles/sveltekit_static_dynamic
If you sync the latest version of that, you can “npm run dev” and everything works using the backend proxy. But “npm run build” fails. It seems like adapter static should just ignore any +server.js files.
Logs
No response
System Info
System:
OS: macOS 12.2.1
CPU: (8) arm64 Apple M1
Memory: 141.84 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.10.0 - ~/.nvm/versions/node/v18.10.0/bin/node
npm: 8.19.2 - ~/.nvm/versions/node/v18.10.0/bin/npm
Browsers:
Firefox: 105.0.1
Safari: 15.3
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.80
@sveltejs/adapter-static: ^1.0.0-next.44 => 1.0.0-next.44
@sveltejs/kit: next => 1.0.0-next.511
svelte: ^3.44.0 => 3.50.1
vite: ^3.1.0 => 3.1.6
Severity
blocking an upgrade
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:36 (27 by maintainers)

Top Related StackOverflow Question
@Rich-Harris @gbkwiatt Think there is some confusion with how we are using
adapater-statichere. We’ve been using adapter-static for over a year now and without problems until the recent changes.We have normal page routes like
/jacks-page/+page.svelteand on these pages we have simple get requests to some of our server routes. For example we have a server route to handle all of our images (as they’re stored on a CMS) so we have/images/[...slug]/+server.jsso when/jacks-pagerequests/images/homepage.jpgit gets handled by the server route and produces a jpg file which can be downloaded and stored when crawling and statically generating the site.We have many of these server routes like this, some which produce images, some produce json files. We obviously don’t want these server routes to be directly prerendered themselves because that doesn’t make sense. However, we require them to be present and running when the crawler is statically generating the site.
So with the new changes to the routing system, how would we achieve what we were doing before? We’ve tried converting our old server routes to the new
+server.jsformat and addingexport const prerender = false;to the top, however adapter static tries prerendering them anyway (which fails) and seems to ignore the prerender option.Your comment earlier suggested we need to use a different adapter instead of
adapter-static. We’re open to picking another one as long as the end result is a fully statically generated site, which adapter are you recommending?I found out that for some reason even that I have +layout.js in a root with prerender true, I still have to mark some of the routes as prerender true with separated layout.js inside that route. Also it could have something to do with option in a config
config.kit.prerender.entriesto be honest it’s more of a try and fail game.