Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter Static is buggy #10433

Closed
DanielRios549 opened this issue Jul 25, 2023 · 6 comments · Fixed by #10443
Closed

Adapter Static is buggy #10433

DanielRios549 opened this issue Jul 25, 2023 · 6 comments · Fixed by #10443

Comments

@DanielRios549
Copy link

Describe the bug

I have a project with two dynamic nested routes: /[name]/[project]. During development I know what name and project should be, the route should be something like /daniel/portfolio.

I was using SvelteKit beta from Feb 2022 version 1.0.0-next.267, on the sveltekit.config.js I created an array of entries that correspond to all possibilities of [name] and [project]params, so the final array on prerender.entriesis ['*', '/daniel/portfolio'].

The build works flawlessly, generating the /daniel.html and /daniel/portfolio.html like it was supposed to be.

This is with SvelteKit 1.0.0-next.267and adapter static 1.0.0-next.26. Using up-to-date packages, no matter what I do, the build simply does not work, I use the same configuration on svelte.config.js, I use the entries function to get the value of [name] and [project] params, nothing works, the adapter-static says all routes are dynamic, even absolute static ones like test/+page.svelte with only a h1 inside.

How to make this thing work?!

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-c1arfw?file=svelte.config.js

Logs

No response

System Info

System:
    OS: Linux 5.15 KDE neon 5.26 5.26
    CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
    Memory: 6.45 GB / 15.57 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.17.0 - ~/.asdf/installs/nodejs/16.17.0/bin/node
    Yarn: 1.22.19 - ~/.local/bin/yarn
    npm: 8.15.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 6.14.2 - ~/.local/bin/pnpm
  Browsers:
    Chrome: 114.0.5735.198
  npmPackages:
    @sveltejs/adapter-static: ^2.0.2 => 2.0.2 
    @sveltejs/kit: ^1.22.3 => 1.22.3 
    svelte: ^4.1.1 => 4.1.1 
    vite: ^4.4.7 => 4.4.7

Severity

blocking an upgrade

Additional Information

No response

@infovore
Copy link

infovore commented Jul 27, 2023

You're not exporting const prerender = true for any of the name/project pages, which is now required, from what I recall; you have it on your root +page.ts; you might want to add it to src/+layout.ts if you want to prerender the entire site; this is what the documentation recommends.

That's my first thought - I think I ran into this a while back.

In addition, as a stylistic tip, it's now possible to export entries from routes that you want to prerender, meaning you can locate the logic to determine those routes closer to where they belong. config.kit.prerender.entries should work fine though.

@eltigerchino
Copy link
Member

eltigerchino commented Jul 27, 2023

There was a change where you have to explicitly mention that all pages are pre-renderable by adding the following setting. This is also mentioned in the error message when the build fails in your reproduction.
https://kit.svelte.dev/docs/adapter-static#usage

// src/routes/+layout.js
export const prerender = true;

I've added the file and the build completes successfully. Can you confirm if the following output is what you expected?
https://stackblitz.com/edit/sveltejs-kit-template-default-wzfz7p?file=src%2Froutes%2F%2Blayout.js

EDIT: whoops, someone posted a better explanation earlier.

@DanielRios549
Copy link
Author

@infovore and @s3812497 I forgot to add the export const pretender = true in this Stackblitz Project.

It builds the project now, different from my local project, I don't know why in my machine it does not work, but I'll try to figure it out based on this Stackblitz Project.

@DanielRios549
Copy link
Author

DanielRios549 commented Jul 27, 2023

@s3812497 The issue is not resolved yet. If you see the StackBlitz Project, I added a route called test in the [name] route, with this route the builds say this route is marked as prerenderable, but were not prerendered because they were not found while crawling your app.

So I added a +page.ts to [name]/test route and added export const prerender = falseto it.

Now it simply bugs everything and says all pages are dynamic:

@sveltejs/adapter-static: all routes must be fully prerenderable, but found the following routes that are dynamic:
    - src/routes/
    - src/routes/api/get-all
    - src/routes/[name]
    - src/routes/[name]/test
    - src/routes/[name]/[project]

This is the bug I'm having right now to update the app, as I fixed all the issues it says everything is dynamic...

@eltigerchino eltigerchino reopened this Jul 27, 2023
@eltigerchino
Copy link
Member

So I added a +page.ts to [name]/test route and added export const prerender = falseto it.
Now it simply bugs everything and says all pages are dynamic:

The builder error message is definitely confusing because it lists all your routes when it should only list the problematic one (which is src/routes/[name]/test).

When using adapter-static all of your pages must be set to prerender = true (usually in the root layout).

I added a route called test in the [name] route, with this route the builds say this route is marked as prerenderable, but were not prerendered because they were not found while crawling your app.

Your pages must be discoverable either by including it in a link somewhere in your app or specifying it with entries. See https://kit.svelte.dev/docs/page-options#entries for more information.

@infovore
Copy link

infovore commented Jul 27, 2023

+1 to what @s3812497 said:

  • if you've said a page is not prerenderable, that will cause an error in adapter-static; it's strange you're seeing all those paths mentioned - that feels like a bug - but the fact the build process throws an error is correct: you are trying to build a static site and have flagged a page as not static. So let's remove export const prerender = false
  • if none of your pages link to /[name]/test - eg /daniel/test - then that route doesn't get crawled to prerender, and this leads to an error. the solution is to link to it, or to add it to entries. For instance, in your function that generates the data for entries you could write this:
data.projects.forEach(({ name }) => {
    links.push(`/${user}/${name}`);
    links.push(`/${user}/test`);
});

(or, indeed, add test to the list of names in JSON)

  • now, you can prerender it, although it'll still 500 without a matching +page.svelte. So I add that and your code now runs.

Here's a stackblitz where this works.

I don't understand why +page.ts would not be prerenderable, if you are trying to make a prerenderable site?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants