Skip to content
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's config setting resolve.conditions isn't respected when recursing through dependencies. #1588

Closed
6 tasks done
thislooksfun opened this issue Jul 4, 2022 · 5 comments

Comments

@thislooksfun
Copy link

thislooksfun commented Jul 4, 2022

Describe the bug

When vitest is recursing through the dependencies in node_modules it loses track of the resolve.conditions setting, meaning that nested imports with conditional exports resolve to the wrong file.

Reproduction

https://github.com/thislooksfun/vitest-mre

System Info

Not relevant to the bug.

Used Package Manager

npm

Validations

@thislooksfun
Copy link
Author

Vitest also doesn't respect Vite's default resolve.conditions — if you load the linked MRE and comment out the resolve.conditions in the vite.config.js file then both tests will fail — but that might be better reported as a separate issue.

@sheremet-va
Copy link
Member

sheremet-va commented Jul 4, 2022

Use test.deps.inline for node_modules, if you need to apply Vite transforms to it.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2022
@sheremet-va
Copy link
Member

sheremet-va commented Jul 4, 2022

but that might be better reported as a separate issue.

This is nog a bug, Vitest processes files with SSR flag, which mean browser condition is not respected. This is intentional - a lot of dependencies will just not work with browser field in Node.

The other reason we shouldn't use browser is because by default Vitest is Node test runner, without access to browser API, and that wouldn't make sense.

@thislooksfun
Copy link
Author

Ok, that's a decent reason to have different defaults, but it's not actually a response to this bug. If you look at the MRE I made, the "shallow" import DOES respect resolve.conditions, while the "deep" import DOES NOT. Either way this is unintended behavior, and is not surfaced to the user in understandable ways. Either way you cut it this is unintended behavior that causes really confusing behavior like solidjs/solid-testing-library#10. Either fully respect resolve.conditions or don't respect it at all.

@sheremet-va
Copy link
Member

We respect resolve.condition for all processed files. node_modules files are not processed by default, and their execution is delegated to Node for performance reasons. If you need to process them, use test.deps.inline, as I already said.

If there is a way to provide condition to Node directly, we could add it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants