Usage of import.meta.env #2646
Unanswered
damianstasik
asked this question in
General
Replies: 1 comment 3 replies
-
Thanks for reporting! I was skeptical about it, but nobody has reported until now... Does
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've noticed a small issue with how the
(import.meta.env ? import.meta.env.MODE : undefined)
condition is processed in code built by Vite. In short,import.meta.env
in this condition gets replaced by a reference to an object containing all environment variables. Here's a snippet from a fresh Vite app using zustand:As you can see, the condition and the warning are still present even though the code was built with
MODE: "production"
. For some apps, this might not be an issue, but if you have many environment variables or some very long ones, it could be problematic. Depending on how many zustand modules end up in the bundle, you can get 4-5 of these objects, and each will contain all environment variables.Would you consider using only
process.env.NODE_ENV
to check the environment? Most tools support it out of the box, whereasimport.meta.env
is a Vite-specific feature, though I wish it were standard.Beta Was this translation helpful? Give feedback.
All reactions