-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.env
files are not loaded
#1148
Comments
I have just this minute hit the exact same issue. I have a Vue 3 application built with Vite and tested with Vitest. I created a |
@meoyawn reproduction works, if I add |
@kpturner can you give me a reproduction, when it works with Vite, but doesn't work in Vitest? |
@sheremet-va do I understand correctly that |
tried setting
Really hoped I could use |
Yes, Vite exposes only env variables starting with |
@sheremet-va it works! Thank you so much |
Not sure why this was closed when I have been asked to provide a repo where it doesn't work in vitest even with environment variables with. "VITE_" prefix? Do you now not want a repo showing this? |
@sheremet-va This is the repro repo: https://github.com/kpturner/vitest-github-repro |
Hey, your issue is with this code:
This overrides I will make a patch that removes it inside a Vitest plugin in the future to not case confusion. |
Excellent - thanks |
@kpturner sorry closing the issue prematurely was my mistake |
If I understand the problem correctly, then vitest already has a solution for this: https://vitest.dev/config/#setupfiles I simply had to add the line Example repo: https://github.com/repetitioestmaterstudiorum/ts-boiler/blob/master/vitest.config.ts |
Vite has a specific way of loading the .env files (.env.development based on NODE_ENV=development for example). I believe Vitest should do the same (or at least provide the option)? |
Vite doesn't populate |
Describe the bug
There's an
envDir
section in Vite docs https://vitejs.dev/config/#envdir saying that.env
files are loaded fromroot
dir by default.But neither
.env
nor.env.test
file is loaded in vitest 0.9.3Reproduction
https://github.com/meoyawn/vitest-env
System Info
System: OS: macOS 11.6.2 CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz Memory: 2.65 GB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 17.9.0 - /usr/local/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.5.5 - /usr/local/bin/npm Browsers: Brave Browser: 98.1.35.101 Chrome: 100.0.4896.88 Firefox: 92.0 Safari: 15.2 npmPackages: vitest: ^0.9.3 => 0.9.3
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: