question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

adapter-static has issues with server endpoints

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:7
  • Comments:36 (27 by maintainers)

github_iconTop GitHub Comments

4reactions
JackPriceBurnscommented, Oct 11, 2022

@Rich-Harris @gbkwiatt Think there is some confusion with how we are using adapater-static here. 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.svelte and 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.js so when /jacks-page requests /images/homepage.jpg it 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.js format and adding export 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?

The reason we’re using a sveltekit route to proxy requests to an external image source is because we want to store those images in the statically generated site, and deploy that to a CDN (we use CloudFlare). This way we don’t have to worry about our CMS going down or anything like that.

3reactions
gbkwiattcommented, Oct 13, 2022

I’m thoroughly confused at this point. I have a site with completely static content (not a single .js file) and adapter-static still complains that that the routes must be “fully prerenderable”.

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.entries to be honest it’s more of a try and fail game.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Demo app cannot be built with the static adapter ... - GitHub
Describe the bug PR3679 has broken the demo application build process for static adapter. It now shows a 500 error when doing build....
Read more >
@sveltejs/adapter-static - npm
@sveltejs/adapter-static. Adapter for SvelteKit apps that prerenders your entire site as a collection of static files.
Read more >
How to host a project built with adapter-static and dynamic ...
If you had access to a Node server, dynamic routing should not be an issue (using @sveltejs/adapter-node ), which again depends on the ......
Read more >
What and why: static-adapter : r/sveltejs - Reddit
The endpoints JS runs on the node server. Is the endpoints part the only real difference?
Read more >
Adapters • Docs • SvelteKit
Most adapters will generate static HTML for any prerenderable pages of your site. In some cases, your entire app might be prerenderable, in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found