Environment variables inconsistencies
Documentation is
- [ ] Missing
- [ ] Outdated
- [X] Confusing
- [ ] Not sure?
Explain in Detail
In the config page it says
Environmental Variables can be obtained from process.env as usual.
and
Note that Vite doesn't load .env files by default as the files to load can only be determined after evaluating the Vite config, for example, the root and envDir options affect the loading behaviour. However, you can use the exported loadEnv helper to load the specific .env file if needed.
Which is not what I've experienced. process.env is not working (very unfortunate choice, made a lot of headache to developers, but I'm sure there's a good reason for it).
On the other hand in [the Env and Mode page], it says
Vite exposes env variables on the special import.meta.env object, and
Vite uses dotenv to load additional environment variables from the following files in your environment directory:
Your Suggestion for Changes
Choose one version, and stick with it.
Reproduction
No response
Steps to reproduce
No response
The env var docs in the config page applies to the vite config. The env var docs in "env and mode" applies to the vite app. I think they're both correct to me right now. Is there something specific that's confusing?
About process.env, it's mentioning that the usual way of accessing it, like in usual node scripts, will still work. The .env doesn't interfere with it, if that's what you mean.
Instead of process.env in VITE we can use meta.env in node we use processe.env to load environmental variables .
Closing as there hasn't been a response from OP