-
Notifications
You must be signed in to change notification settings - Fork 6
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
Added import.meta.env
for environment variables
#5
Conversation
import.meta.env
for environment variables
|
Yes, but environment variables do not change based on the current file - they are the same in every file. |
FWIW, this is actively in use by Vite, bun, and rspack today.
It seems like adding it to this repo could reduce the risk of somebody adding a conflicting property to another runtime? I'm not arguing that |
My main grip was on how weird Cloudflare is and this is the main reason I even started this, since I'd like to be able to access the environment properties outside of fetch(), however it's true that it'd be nice for the others to be the same. @ljharb I'll let you decide here whether to close this issue or not, your arguments are very true and this is not "the right place" (even though I initially proposed this), however @jkrems is also right this is becoming more and more common and we'd benefit from an official place that documents/recommends it this way. |
I suppose the Cloudflare env vars as secrets thing is actually an argument for contextual |
There's likely also some finer details around mutability. E.g. I assume |
I simply don't think there's any argument for it. Environment variables are global within an environment; changing them contextually is a misuse/abuse of the feature; if we want contextual values per-module than "env" is simply the wrong name for the concept. Additionally, |
Contextual secrets make a lot of sense to me as a concept personally. So far as folks use environment variables for secrets, techniques like this may allow them to use them more safely by allow-listing environment variables per module consumer. |
Contextual secrets are clearly valuable and useful and important - I just don't think it makes any sense to subvert environment variables for that purpose. Let's work across the runtimes and come up with a way to do it that's actually intended for that purpose :-) |
So far as this meta registry is concerned, the value in standardizing patterns is in ensuring coordination between runtimes. If more tools and runtimes continue to adopt this pattern, we cannot gate landing the spec for the pattern on coming up with something better. |
That’s true. But we can advise them not to propagate a pattern further if we’re working on a better alternative. |
I think contextual secrets are different, I do want my env variables to be accessible by my modules in 99% of the cases, in fact I wish more modules would directly read those instead of having to manually pass them all around.
So the conclusion is that |
Contextual secrets certainly shouldn't be on |
Oh sorry yeah, "this" I meant environment variables should go within |
See relevant Github for all of the details, but basically this proposal is for a single place where the Environment Variables are all already loaded from the environment:
If this is relevant, I can also add a polyfill and some test, so please let me know and I can add those!