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

Warn when browser or dev are used #8033

Closed
benmccann opened this issue Dec 9, 2022 · 5 comments
Closed

Warn when browser or dev are used #8033

benmccann opened this issue Dec 9, 2022 · 5 comments
Labels
feature / enhancement New feature or request pkg:svelte-package Issues related to svelte-package
Milestone

Comments

@benmccann
Copy link
Member

benmccann commented Dec 9, 2022

Describe the problem

People use import { browser, dev } from '$app/environment' and then their packages end up being tied to SvelteKit and Vite when they should work with any Svelte project

Describe the proposed solution

Print a big loud warning when running svelte-package if anyone tries to use import.meta.env.SSR, import { browser, dev } from '$app/environment', etc. and tell them to use import { BROWSER, DEV } from 'esm-env' unless they intend for their package to only be used in SvelteKit

Put a warning in the docs not to use these for libraries

Alternatives considered

Get rid of import { browser, dev } from '$app/environment' and just tell people to use esm-env in the docs. I think I'd prefer that honestly, but it couldn't be done until SvelteKit 2 as it's a breaking change

Importance

nice to have

Additional Information

No response

@Tal500
Copy link
Contributor

Tal500 commented Dec 12, 2022

Please notice @benmccann that there is a problem with the REPL, I filled up an issue: benmccann/esm-env#1

@Conduitry
Copy link
Member

We should move forward with this change regardless. Using $app/environment in components already doesn't work in the REPL, and so pushing people towards esm-env won't make them worse off. The REPL is a lot more likely to support exports maps in the future than it is to ever support a hacky workaround specifically for $app/environment when that's syntac we discourage people from using anywhere else.

@orefalo
Copy link

orefalo commented Dec 13, 2022

Hi, can you have a look at https://github.com/Tal500/esm-env-robust and confirm it's a valid workaround for the expected behavior?
If it is, can we push the code upstream to the svelte kit implementation, so that the environment api behaves as expected?

@benmccann benmccann added the feature / enhancement New feature or request label Jan 20, 2023
@Glench
Copy link

Glench commented Feb 14, 2023

Would really love to use the alternative — use esm-env directly. I'm running into issues trying to use stuff in my SvelteKit app in utility scripts and in the node REPL.

@ghostdevv
Copy link
Member

Should be able to close this now

'Avoid usage of `$app/environment` in your code, if you want to library to work for people not using SvelteKit (only regular Svelte, for example). ' +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

No branches or pull requests

7 participants