I want to load environment variables from the .env file using Vite
I used the import.meta.env object as mentioned in Docs
.env file:
TEST_VAR=123F
when trying to access this variable via the import.meta.env -> import.meta.env.TEST_VAR it returns undefined.
so, how can I access them?
According to the docs, you need to prefix your variables with
VITE_:If you are trying to access env vars outside your app source code (such as inside
vite.config.js), then you have to useloadEnv():For SvelteKit