Usage of import.meta.env #2646
Replies: 2 comments 4 replies
-
Thanks for reporting! I was skeptical about it, but nobody has reported until now... Does
|
Beta Was this translation helpful? Give feedback.
-
Not too deep into the topic, but since we've experienced it as well, It is because vite is checking bare import from this line? I think possible side effect is when there are github env vars/secrets prefixed |
Beta Was this translation helpful? Give feedback.
-
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