vitest: Don't respect `conditions` on Vite 6
Describe the bug
resolve.conditionsis not respected on Vite 6 with Vitest.- It works on Vite 6 without Vitest.
- It works on Vite 5.
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
resolve: {
conditions: ['dev'],
},
})
Reproduction
https://stackblitz.com/~/github.com/sxzz/vitest-conditions-repro
- Run
pnpm run test, and you will see the test has failed. - Downgrade to vite@5, remove
node_modulesandpnpm-lock.yaml, and it works.
System Info
N/A
Used 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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 19 (13 by maintainers)
Commits related to this issue
- test: fix custom resolver conditions on Vite 6 + Vitest See https://github.com/vitest-dev/vitest/issues/6992 — committed to vue-macros/vue-macros by sxzz 2 years ago
- fix: custom resolver conditions on ssr environment closes #6992 — committed to sxzz/vitest by sxzz 2 years ago
- chore: pin to vitest 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vite 6 — committed to Cherry/workers-sdk by Cherry 2 years ago
- chore: pin vitest to 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vite 6 — committed to Cherry/cloudflare-docs by Cherry 2 years ago
- fix: revert support for Vite 6 Related https://github.com/vitest-dev/vitest/issues/6992 — committed to vitest-dev/vitest by sheremet-va 2 years ago
- chore(deps): update dependency vitest to v2.1.7 ##### [v2.1.7](https://github.com/vitest-dev/vitest/releases/tag/v2.1.7) ##### 🐞 Bug Fixes - Revert support for Vite 6 - by [@sheremet-va](ht... — committed to mmkal/eslint-plugin-mmkal by renovate[bot] 2 years ago
- chore: pin to vitest 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vite 6 — committed to Cherry/workers-sdk by Cherry 2 years ago
- chore: pin to vitest 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vite 6 — committed to Cherry/workers-sdk by Cherry 2 years ago
- chore: bump vitest in templates (#7384) * chore: bump vitest in templates * chore: pin to vitest 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vit... — committed to cloudflare/workers-sdk by Cherry 2 years ago
- Squashed commit of the following: commit 094699c6a218caa1c0ed5dcfb8f75598bc1f503c Merge: 21bfe2a5b 5ea9d8e9f Author: Samuel Macleod <smacleod@cloudflare.com> Date: Fri Dec 6 00:36:04 2024 +0000 ... — committed to cloudflare/workers-sdk by penalosa 2 years ago
- [Workers] fix: update supported vitest version (#18474) * fix: update supported vitest version * chore: pin vitest to 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being ... — committed to cloudflare/cloudflare-docs by Cherry 2 years ago
- chore: bump vitest in templates (#7384) * chore: bump vitest in templates * chore: pin to vitest 2.1.5 This works around https://github.com/vitest-dev/vitest/issues/6992 being an issue with Vit... — committed to cloudflare/workers-sdk by Cherry 2 years ago
There will be no more Vitest 2 versions. Vitest 3 is the first version that supports Vite 6 (excluding 2.1.6)
https://github.com/vitest-dev/vitest/releases/tag/v2.1.7 reverted support for Vite 6 for now. We will discuss with the team on how to introduce it without breaking changes.
We will be releasing Vitest 3 in January with this change instead of Vitest 2.2. Both Vite 5 and Vite 6 will be supported, but the behaviour will depend on the version installed by your package manager.
I think this needs to be considered a breaking change with
vitest2.1.5->2.1.6. While I understand vitest supports 5.x and 6.x versions ofvitenow, in projects that don’t usevite6.xis now automatically used over5.xin a patch version, which can result in drastically different behaviour.For example, with Cloudflare’s
vitest-pool-workerswhich is used for testing Cloudflare Workers, they rely heavily on settingconditions: https://github.com/cloudflare/workers-sdk/blob/ff8f5ae03cd4a71bf7b468fcf3cd28bf064059ab/packages/vitest-pool-workers/src/config/index.ts#L110-L113Most Cloudflare Workers don’t use
viteto build though, so don’t havevitepinned to5.x, resulting in breaking behaviour when upgrading fromvitest2.1.5to2.1.6, which just happened to me and led me down this rabbit hole.I don’t think this is part of Vitest API, this is how Vite works. If you don’t want to use Vite 6, use Vite 5. We support both versions and just follow the configuration supported by the version of Vite that you are using.
This is expected behaviour in Vite 6: https://vite.dev/guide/migration.html#general-changes
Vitest uses
ssrenvironment innodeVitest environment (previously,ssrfield in the config), andclientenvironment injsdomorhappy-dom(previously, the root config)We can add this to documentation
Workaround: Adding
environments.ssr.resolve.conditionscan fix this issue.Also experiencing this issue, but I’m not using vite, it’s the bump of vitest to v2.1.6 that is causing the issue for me, sticking to v2.1.5 for now