kit
kit copied to clipboard
Warn when `browser` or `dev` are used
Describe the problem
People use import { browser, dev } from '$app/environment' and then their packages end up being tied to SvelteKit 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 { browser, dev } from '$app/environment' 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
Resolve aliases during packaging https://github.com/sveltejs/kit/issues/1950
Get rid of import { browser, dev } from '$app/environment'
Importance
nice to have
Additional Information
No response
Please notice @benmccann that there is a problem with the REPL, I filled up an issue: https://github.com/benmccann/esm-env/issues/1
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.
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?
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.
Should be able to close this now
https://github.com/sveltejs/kit/blob/72436944dff4ebdc47b3ab212169fb7924574714/packages/package/src/validate.js#L46