Open khromov opened 2 months ago
I'm not sure if this is something we can fix, arguably it's a misconfiguration. IIRC we have some specific logic to ensure env variables are available before the rest which involves code splitting, and this may undo that logic
@dummdidumm I don't really have any interest in fiddling with the server builds, but I would like to reduce the amount of built client side JS files using this approach.
It was suggested to apply the manualChunks config conditionally to only client builds, but isSsrBuild flag is broken and always returns false, so it's not currently possible to do that.
Describe the bug
If you try to access $env/dynamic/private during application startup (for example at top level of hooks) then
env
is empty ({}
) ONLY whenmanualChunks
configuration is set.Reproduction
Repo: https://github.com/khromov/env-var-manualchunks-repro
SvelteKit manualChunks bug explanation
Broken version:
FOO is undefined although we set it.
But when going to http://localhost:3000/ we get it:
Then, remove the
manualChunks
option fromvite.config.ts
and run again:Now FOO is set and works correctly both during init and on web.
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response