-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Copy link
Labels
Description
Describe the bug
I have a config with several defines in it:
{
define: {
'import.meta.env.FOO': JSON.stringify(process.env.FOO),
'import.meta.env.BAR': JSON.stringify(process.env.BAR),
}
}This follows the recommendation from https://vite.dev/config/shared-options#envprefix. This works as expected in Vite - however in Vitest Browser Mode they are undefined. I have set my config to extend the main config, and other values work such as:
{
define: {
'__FOO__': JSON.stringify(process.env.FOO),
'__BAR__': JSON.stringify(process.env.BAR),
}
}However the usage with import.meta.env does not seem to work as expected.
Reproduction
Can produce a skeleton repo if required
System Info
System:
OS: macOS 15.7.2
CPU: (10) arm64 Apple M1 Pro
Memory: 191.08 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - /Users/me/.nvm/versions/node/v22.14.0/bin/node
npm: 11.6.2 - /Users/me/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 9.15.6 - /Users/me/.nvm/versions/node/v22.14.0/bin/pnpm
Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 143.0.7499.41
Firefox: 145.0.2
Safari: 26.0.1
npmPackages:
@vitest/coverage-istanbul: ^4.0.15 => 4.0.15
@vitest/ui: ^4.0.15 => 4.0.15
vite: ^7.2.6 => 7.2.6
vitest: ^4.0.15 => 4.0.15
vitest-browser-react: ^2.0.2 => 2.0.2Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable