kit
kit copied to clipboard
Cannot build project in SPA mode (v1.0.0)
Describe the bug
I just created a new SvelteKit project and followed the instructions to switch to SPA mode. Running the project locally works as expected but when trying to build it, I get an error (see logs).
I tried all the suggestions in the error log and in the adapter-static
home page, but none of them worked.
I have an older project of mine where my SvelteKit version is 1.0.0-next.528
and adapter-static
is 1.0.0-next.46
and I can both run the project locally and build it.
So this bug must have been introduced in a later version.
Reproduction
- Create a new SvelteKit project (read more)
- Install
adapter-static
-npm i -D @sveltejs/adapter-static
- Update
svelte.config.js
to the following:
// svelte.config.js
import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({
fallback: 'app.html'
}),
prerender: { entries: [] }
}
};
- Create a
layout.js
(or.ts
) in/routes
- Add the following to
layout.js
-export const ssr = false;
- Run
npm run build
Logs
> Using @sveltejs/adapter-static
@sveltejs/adapter-static: all routes must be fully prerenderable, but found the following routes that are dynamic:
- src/routes/
You have the following options:
- set the `fallback` option — see https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode for more info.
- add `export const prerender = true` to your root `+layout.js/.ts` or `+layout.server.js/.ts` file. This will try to prerender all pages.
- add `export const prerender = true` to any `+server.js/ts` files that are not fetched by page `load` functions.
- pass `strict: false` to `adapter-static` to ignore this error. Only do this if you are sure you don't need the routes in question in your final app, as they will be unavailable. See https://github.com/sveltejs/kit/tree/master/packages/adapter-static#strict for more info.
If this doesn't help, you may need to use a different adapter. @sveltejs/adapter-static can only be used for sites that don't need a server for dynamic rendering, and can run on just a static file server.
See https://kit.svelte.dev/docs/page-options#prerender for more details
error during build:
Error: Encountered dynamic routes
at adapt (file:///Users/yulian/Code/svelte-latest/node_modules/@sveltejs/adapter-static/index.js:53:12)
at adapt (file:///Users/yulian/Code/svelte-latest/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:8)
at Object.handler (file:///Users/yulian/Code/svelte-latest/node_modules/@sveltejs/kit/src/exports/vite/index.js:611:12)
at async PluginDriver.hookParallel (file:///Users/yulian/Code/svelte-latest/node_modules/rollup/dist/es/shared/rollup.js:23482:17)
at async Object.close (file:///Users/yulian/Code/svelte-latest/node_modules/rollup/dist/es/shared/rollup.js:24837:13)
at async Promise.all (index 0)
at async build (file:///Users/yulian/Code/svelte-latest/node_modules/vite/dist/node/chunks/dep-0bae2027.js:44326:13)
at async CAC.<anonymous> (file:///Users/yulian/Code/svelte-latest/node_modules/vite/dist/node/cli.js:808:9)
System Info
System:
OS: macOS 13.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 47.89 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.2.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.19.3 - /usr/local/bin/npm
Browsers:
Brave Browser: 108.1.46.144
Chrome: 108.0.5359.124
Firefox: 105.0.1
Safari: 16.2
npmPackages:
@sveltejs/adapter-auto: ^1.0.0 => 1.0.0
@sveltejs/adapter-static: ^1.0.0 => 1.0.0
@sveltejs/kit: ^1.0.0 => 1.0.1
svelte: ^3.54.0 => 3.55.0
vite: ^4.0.0 => 4.0.3
Severity
serious, but I can work around it
Additional Information
Technically it's blocking an upgrade but I can postpone it for now.
I can't reproduce this given the steps. Please provide a reproduction repository.
@dummdidumm Here it is: https://github.com/yuliankarapetkov/svelte-latest
@yuliankarapetkov ~~please add prerender = true
with ssr = false
.~~
There seems to be a mistake in the configuration. https://github.com/yuliankarapetkov/svelte-latest/blob/master/svelte.config.js#L10-L19
The following will fix it.
kit: {
adapter: adapter({
fallback: 'app.html'
}),
prerender: { entries: [] }
}
Had a similar problem with the following error on the build:
error during build:
Error: The fallback option no longer exists — use builder.generateFallback(fallback) instead
The problem was with the wrong version of @sveltejs/adapter-static, which was still set on 1.0.0-next.48. Updating to latest solved everything.
There seems to be a mistake in the configuration. https://github.com/yuliankarapetkov/svelte-latest/blob/master/svelte.config.js#L10-L19
Oh wow, how did I miss that! I'm sorry! 🤦♂️
Fixing the config and adding prerender = false
both fixed the issue for me. Thank you!
Closing as the issue has been resolved