vitest-dev / vitest-dev/vitest
import.meta.env.BASE_URL vite built-in constant breaks with vitest 4.x
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
With vitest 4.x the vite built-in import.meta.env.BASE_URL no longer has the expected value set (base from the vite config as per docs).
For example if I have a component that displays the value of import.meta.env.BASE_URL doing a regular vite the value is displayed as expected.
If I now write a test with vitest 4.x that asserts for this value, the test breaks because the value is just / regardless of what is set in the base field of the vite config.
Reproduction
Small example project here
If you run vitest run with vitest version 4.0.6 for example, the one test asserting for the BASE_URL value will fail.
If you switch the vitest version to a 3.x version 3.2.4 for example, all tests succeed.
System Info
System:
OS: Windows 11 10.0.22631
CPU: (24) x64 12th Gen Intel(R) Core(TM) i7-12850HX
Memory: 28.41 GB / 63.61 GB
Binaries:
Node: 22.14.0
npm: 10.9.2
pnpm: 10.8.1
Browsers:
Chrome: 141.0.7390.123
Edge: Chromium (140.0.3485.54)
Internet Explorer: 11.0.22621.3527
npmPackages:
@vitejs/plugin-vue: ^6.0.1 => 6.0.1
vite: ^7.1.7 => 7.1.12
vitest: ^4.0.6 => 4.0.6
Used Package Manager
npm
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked minimal reproduction and run vitest run using Vitest 4.0.6, then compare its result with Vitest 3.2.4. Trace how the test environment supplies import.meta.env.BASE_URL relative to the Vite base configuration. Done means the assertion receives the configured base value under Vitest 4.x.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100