-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unable to entirely disable prerendering #7899
Comments
Could you try setting the |
This is expected — it's a result of this change, which ensures that SvelteKit can analyse your code in order to configure deployments in future. That said, importing and analysing your code is one thing; actually rendering stuff (the fallback) is something else, since it means having to do By the way, it's better to import env vars from |
(To expand: the reason this is unfortunate is that the fallback page is always generated but only rarely used. There's a tricky order-of-operations thing — if you're using |
Thanks for your thoughts, both. I'm aware of the I want to reiterate my thanks to you both (@Rich-Harris and @dummdidumm) and the wider team. Kit is a fantastic piece of work, and your recent breaking changes are so much better for ergonomics. Well done for being brave and sticking to doing the best you can for v1. Exciting days are very close now. |
@georgecrawford I was the lost soul trying to help you on Discord. |
I have also faced this issue since I'm making API calls in server hooks. |
Same. There should definitely be some sort of a global option to let users opt out of everything prerendering-related entirely. This area is still confusing. |
It looks like #7878 released in version 573 also made this issue more salient. We still have a lot of legacy code in our app that uses Angular 1 (aka AngularJS), and just importing Until version 573, this worked fine since the prerendering code was surrounded with try/catch which would basically ignore any errors. But at https://github.com/sveltejs/kit/pull/7878/files#diff-640bb06029f8b528408cb17e6b0a88cd9d68924246d520db4a616a8a2fe7d4f9L384 this try/catch was removed, and so our app no longer builds. I confirmed that editing the file to add back that try/catch does allow the app to build, but of course that's not a proper solution since in the "normal" case you do want to throw those errors. Note that this is a rather different cause from OP's problem, since we're not doing anything with hooks -- it's the pages themselves and their dependencies that import |
@dimfeld Are you importing If you are importing |
Indirectly, yes, by importing other packages in our monorepo which in turn import But we're not running anything Svelte-related on the server though -- we build with adapter-static and just serve the JS/CSS/HTML directly from nginx. The app has been running in production with the SvelteKit/Angular hybrid since last year and managed the big routing change just fine, so I can confirm it does work at runtime :) But that's a good point though... Most of our usage is in the |
Interesting — I don't quite understand how you're able to build the site with |
We're running a "SPA-mode" setup. Prerendering disabled as much as we can with Anyway, I think the details are moot for now, since I just confirmed that it does work to deep-import the specific files that we need so that It's been a long process getting Angular slowly stripped out of our 8-year-old app, can't wait to get it finished and be 100% on SvelteKit :) |
Thanks again, @Rich-Harris and @dummdidumm! |
Describe the bug
Hi,
Forgive me if I've missed something! I'd like to run SvelteKit as a SSR-and-CSR solution, with no build-time prerendering.
From the docs, I can disable prerendering routes by adding a
export const prerender = false;
annotation to the top-level+layout.js
. This seems to work.I can also prevent the build process from crawling for entries to prerender (
svelte.config.js
):However, despite these two settings, I am still seeing an attempt to prerender when I run
vite build
:I've tracked this down to this code block:
Whereas prerendering known routes and other entries can be disabled with the above config, there doesn't seem to be a way to disable the rendering of the
fallback.html
file. This is a problem for anyone who wants to ship code in server hooks which doesn't work in the environment in whichvite build
is run.Would it be possible to allow this fallback prerendering to be disabled? If not, it'd be great to understand why it's important (somewhere in the documentation), and I guess the only option is for the hooks to make use of
$app/environment.building
or similar to only conditionally run their logic?Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-x9vwcp
This project adds the following changes to the default
https://node.new/sveltekit
:export const prerender = false;
tosrc/routes/+layout.js
export const prerender = true;
from all other routessvelte.config.js
:hooks.server.js
file which relies on environment variables:npm run dev
script to be"UNDECLARED_ENV_VAR_DURING_BUILD='http://testing' vite dev"
so that local dev worksRunning
npm run build
shows that an attempt to prerender the URLhttp://sveltekit-prerender/[fallback]
is still made, and since the environment variable is not declared, the hooks cause the build to fail:One solution I've found for this is the following, in
hooks.server.js
:Is this the recommended approach? If so, it still seems odd to me that I'm unable to disable prerendering across the board.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: