vite icon indicating copy to clipboard operation
vite copied to clipboard

Environment variables inconsistencies

Open Grsz opened this issue 1 year ago • 2 comments

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

Grsz avatar Aug 07 '24 20:08 Grsz

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.

bluwy avatar Aug 08 '24 04:08 bluwy

Instead of process.env in VITE we can use meta.env in node we use processe.env to load environmental variables .

18-05-Amankumarverma avatar Aug 22 '24 13:08 18-05-Amankumarverma

Closing as there hasn't been a response from OP

bluwy avatar Sep 01 '24 13:09 bluwy