Skip to content

[fix] allow SvelteKit to be used without bundling #7950

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

Merged
merged 15 commits into from
Dec 9, 2022
Merged

[fix] allow SvelteKit to be used without bundling #7950

merged 15 commits into from
Dec 9, 2022

Conversation

benmccann
Copy link
Member

@benmccann benmccann commented Dec 5, 2022

Banish import.meta.env from our codebase so that @sveltejs/kit works without bundling

Fixes vitest-dev/vitest#2298 and a ton of other issues I've seen like this around the ecosystem

We should probably print a big loud warning when running svelte-package if anyone tries to use import { browser, dev } from '$app/environment' and tell them to use esm-env unless they intend for their package to only be used in SvelteKit (#8033)

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2022

🦋 Changeset detected

Latest commit: 147c0e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dominikg
Copy link
Member

dominikg commented Dec 5, 2022

this is neat! can we rely on browser and development conditions in exports maps to always be correctly resolved.
As long as it happens in the vite build step i think that is the case, but what about edge runtimes, do they always get output of vite or another bundler? or would there be a point where we have to rely on them to do the right thing with these conditions?

@dominikg
Copy link
Member

dominikg commented Dec 5, 2022

using !browser for ssr a good step for compatibility 👍 otherwise node vs deno vs x would be playing catchup.

@benmccann
Copy link
Member Author

what about edge runtimes, do they always get output of vite or another bundler?

Yes. If they weren't then the code currently in main wouldn't work since those environments wouldn't know how to handle import.meta.env either

Unverified

This user has not yet uploaded their public signing key.
Co-authored-by: Geoff Rich <4992896+geoffrich@users.noreply.github.com>
@benmccann benmccann changed the title [feat] @sveltejs/environment [fix] allow SvelteKit to be used without bundling Dec 5, 2022
@dummdidumm
Copy link
Member

We still have __SVELTEKIT_DEV__ - do we need to keep that because it won't treeshake correctly or is the DEV equivalent from esm-env true at the wrong times?

@benmccann
Copy link
Member Author

Thanks! I wasn't aware of __SVELTEKIT_DEV__. I've replaced it as well. However, doing so causes two tests to fail that I believe is due to a bug that Rich discovered in Vite 3 (vitejs/vite#9203). I fixed it for Vite 4, so after we upgrade, I'll update this branch against master and I imagine those tests should start passing. I'll mark this as a draft until then

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 this pull request may close these issues.

Importing a file which uses "$app/environment": Cannot read properties of undefined (reading 'SSR')
5 participants