-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Vite 6 compatibility issue #7070
Comments
There is no compatibility issue here.
The browser mode doesn't modify resolve conditions. |
I missed this part - we might need to inject default conditions now in the config, but we shouldn't remove the |
Reproducer: So, it does look like the node conditions were still used in the vite 5 case as that test case fails in both versions, but the tslib error when using optimized deps only reproduces in vite 6 since in vite 5, since the "vite:resolve" plugin was going down a different path ( This tslib issue is the failure that drove me down this path, and ultimately what is blocking my teams from adopting Vite 6 at this time. If that issue should be filed with the Vite repo instead, let me know. |
I just want to note that "browser" here is the "happy-dom" environment, not the actual browser, the browser mode in Vitest uses a separate Vite server. |
Yes that's correct. I probably should have been more clear in the naming of the project. I think that's fine and I mainly want things to continue working the same as they do in Vite 5. Since there is no intention of changing away from https://stackblitz.com/edit/vitest-dev-vitest-xzepei6n?file=package.json |
From testing, it looks like adding back in the default conditions for vite >=6 fixes this issue. I'll submit a PR. |
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes vitest-dev#7070
Describe the bug
When using a browser-based evironment (happy-dom, jsdom,
browser), vitest still passesconditions: ['node']
in the resolve config.When using Vite 5, this doesn't really matter because it would infer that we were targetting a web environment and it would resolve in that context anyway. I'm not 100% sure on how this worked before, but
tryNodeResolve
was being passed atargetWeb
boolean and the returned ID will match the browser / default import conditions instead of the node condition.With Vite 6 a lot of this default environment magic was stripped out as part of the Environments api refactor, and now it's just using the resolve.conditions from the corresponding client/ssr configs. This results in a change in behavior where Vitest now uses the node condition for browser environments when using Vite 6.
Using the node condition instead of browser can result in test failures due to differences in behavior between browser and node implementations of a library, but I've also run into issues where esbuild as part of deps optimization generates invalid code where the module itself is "babel compatible" but tries to deconstruct the named exports from
import_mod1.default
instead ofimport_mod1
.These issues reproduce in the latest Vitest
2.1.8
using a resolution for Vite6.0.3
, as well as Vitest3.0.0-beta.2
.Reproduction
I'm still working on creating a reproducer that I can share and should be able to do so by the end of the day.
In terms of the actual code changes, I think these two locations can be changed to use:
vitest/packages/vitest/src/node/plugins/index.ts
Lines 88 to 94 in 4e60333
vitest/packages/vitest/src/node/plugins/workspace.ts
Lines 67 to 73 in 4e60333
But it's also a little unclear to me if we should be clearing out the
mainFields: [],
for the browser-based environments also.System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: