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

no longer able to create adapter-static site where all pages are prerendered #6480

Closed
rburgst opened this issue Aug 31, 2022 · 11 comments
Closed

Comments

@rburgst
Copy link

rburgst commented Aug 31, 2022

Describe the bug

as of #6197 it does not seem to be able to build a fully pre-rendered static site anymore.

We previously used adapter-static along with the

	kit: {
		adapter:
			adapter(),
		        prerender: {
		              entries: allPageUris,

(note that not all pages are reachable via links).

Now I get the error

➤ YN0000: [rb-links-frontend]: Error: config.kit.prerender.default has been removed. You can set it inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197

and

> Using @sveltejs/adapter-static
  @sveltejs/adapter-static: cannot have dynamic routes unless using the 'fallback' option. See https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode for more information
    - src/routes/[slug]
error during build:
Error: Encountered dynamic routes

Reproduction

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

Logs

> Using @sveltejs/adapter-static
  @sveltejs/adapter-static: cannot have dynamic routes unless using the 'fallback' option. See https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode for more information
    - src/routes/todos
error during build:
Error: Encountered dynamic routes
    at adapt@file:///home/projects/sveltejs-kit-template-default-cv4bx4/node_modules/ (sveltejs/adapter-static/index.js:50:12)
    at adapt@file:///home/projects/sveltejs-kit-template-default-cv4bx4/node_modules/ (sveltejs/kit/src/core/adapt/index.js:43:8)
    at handler@file:///home/projects/sveltejs-kit-template-default-cv4bx4/node_modules/ (sveltejs/kit/src/exports/vite/index.js:502:12)
    at <anonymous> (<anonymous>)

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 88.97 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.volta/tools/image/node/16.13.1/bin/node
    Yarn: 3.2.1 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.1.2 - ~/.volta/tools/image/node/16.13.1/bin/npm
    Watchman: 2022.08.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 100.1.37.111
    Chrome: 104.0.5112.101
    Firefox: 103.0.2
    Safari: 15.6.1
  npmPackages:
    @sveltejs/kit: 1.0.0-next.457 => 1.0.0-next.457
    vite: ^3.1.0-beta.1 => 3.1.0-beta.1

Severity

blocking an upgrade

Additional Information

No response

@rburgst
Copy link
Author

rburgst commented Aug 31, 2022

Note that if I add a fallback option and host the generated files on a normal web server, all I get is 404s obviously since no html pages are generated for slug1.html , etc.

@dummdidumm
Copy link
Member

You need to set export const prerender = true inside a +layout.js or +layout.server.js, not inside +layout.svelte

@Conduitry
Copy link
Member

This is essentially a duplicate of #6472. See the improved error message proposed in #6474.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2022
@rburgst
Copy link
Author

rburgst commented Sep 1, 2022

@Conduitry @dummdidumm this gets rid of the error message however it still does not work. I need to specify a fallback option. If I do, then I still dont get the expected output slug1.html, slug2.html.
Basically it appears to me that it is no longer possible with adapter-static to generate a fully static website.

image

@rburgst
Copy link
Author

rburgst commented Sep 1, 2022

to be precise. I dont want a SPA. I want a fully rendered website.

@csjh
Copy link

csjh commented Sep 1, 2022

@Conduitry @dummdidumm this gets rid of the error message however it still does not work. I need to specify a fallback option. If I do, then I still dont get the expected output slug1.html, slug2.html. Basically it appears to me that it is no longer possible with adapter-static to generate a fully static website.

image

Chopping the mutative actions out of todos/+page.server.js and putting export const prerender = true in /+layout.js fixes your issue for me in the reproduction

@rburgst
Copy link
Author

rburgst commented Sep 1, 2022

I updated https://stackblitz.com/edit/sveltejs-kit-template-default-cv4bx4?file=svelte.config.js and deleted the whole todos folder. Still no slug1.html.

Here is the repro repo https://stackblitz.com/edit/sveltejs-kit-template-default-cv4bx4?file=svelte.config.js.

Try and execute npm run build in a shell and check the output in the build folder.

Also note that I have to add a fallback option which enables SPA mode, even if I dont want it.
Can someone point me to a current working example (e.g. a blog) where full static prerendering works?

@csjh
Copy link

csjh commented Sep 1, 2022

I updated https://stackblitz.com/edit/sveltejs-kit-template-default-cv4bx4?file=svelte.config.js and deleted the whole todos folder. Still no slug1.html.

Here is the repro repo https://stackblitz.com/edit/sveltejs-kit-template-default-cv4bx4?file=svelte.config.js.

Try and execute npm run build in a shell and check the output in the build folder.

Also note that I have to add a fallback option which enables SPA mode, even if I dont want it. Can someone point me to a current working example (e.g. a blog) where full static prerendering works?

image

Again, you need to put export const prerender = true in +layout.js, not +page.js

@rburgst
Copy link
Author

rburgst commented Sep 1, 2022

sorry my bad, I had layout.ts not +layout.ts. Now it works! Thanks a lot.
So now there is only a single remaining thing. Since on my real site not all dynamic URLs are reachable via spidering, I am wondering whether there is a replacement for kit.adapter.prerender.entries.

@csjh
Copy link

csjh commented Sep 1, 2022

sorry my bad, I had layout.ts not +layout.ts. Now it works! Thanks a lot. So now there is only a single remaining thing. Since on my real site not all dynamic URLs are reachable via spidering, I am wondering whether there is a replacement for kit.adapter.prerender.entries.

kit.prerender.entries is still a valid part of config

const config = {
	kit: {
		adapter: adapter({ fallback: 'index.html' }),

		// Override http methods in the Todo forms
		methodOverride: {
			allowed: ['PATCH', 'DELETE']
		},

		prerender: {
			entries: [
				"*", "/slug3", "/slug4"
			]
		}
	}
};

@rburgst
Copy link
Author

rburgst commented Sep 1, 2022

hm, I guess then the documentation in https://kit.svelte.dev/docs/configuration#prerender needs a bit of an update since prerender.default is recommended but causes the initial error (and I understood the linked ticket that all prerender options were removed).

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

No branches or pull requests

4 participants