-
-
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
linked dependency causes tests to fail #4032
Comments
I've run into this same error when using Jest and linking local NPM packages which have This issue may have some examples facebook/react#13991. |
Maybe https://vitejs.dev/config/shared-options.html#resolve-dedupe |
Thanks for the suggestions Sadly it did not make the tests pass. Did I maybe add it in the wrong section? What I find interesting is that there is literally no node_modules in the linked dependency and so I kind of don't know how the second react comes into play - but I only have a basic understanding of JS package loading mechanisms like hoisting, etc. |
Any luck here? I'm seeing a similar issue, and adding resolve.dedupe didn't change anything for me either. |
I got a little further: the second react comes from the root library. Apparently it starts searching the directory tree upward from where the actual JS file is ( |
There is |
Thanks for the quick suggestion Sadly the I just saw that the log actually confirms my suspicion that the root react is used:
|
Maybe this will help, I'm working with a linked custom package that reuses the same dependency and solved it with resolve.mainFields and forcing to use use esmodules first. This seems to fix it for me resolve: {
dedupe: ['mobx'], //mobx is in custom linked package and main package
mainFields: ['module', 'main'], //this is needed to work
}, |
I tried adding it: ArloL/vitest-link-reproduction@8de886b but sadly it still fails: https://github.com/ArloL/vitest-link-reproduction/actions/runs/6804415276 |
It looks like adding https://stackblitz.com/edit/github-uvwz3x?file=test-projects%2Fvite-project%2Fvite.config.js Currently While debugging and studying the internal of Vite Running
|
Thanks, @hi-ogawa. What you describe makes perfect sense and I can confirm that it fixes my issue. I am not sure if my assumptions are reasonable but I would expect that |
Good point. I'm testing with To prevent "externalizing" it, I think there is https://stackblitz.com/edit/github-uvwz3x-6kmuvy?file=test-projects%2Fvite-project%2Fvite.config.js import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
dedupe: ['react', 'react-dom', 'react/jsx-runtime'],
preserveSymlinks: true,
},
test: {
environment: 'jsdom',
server: {
deps: {
inline: [/vitest-link-reproduction/],
},
},
},
}); And this what I see when running vite:resolve-details [url] /node_modules/vitest-link-reproduction/dist/vitest-link-reproduction.js -> /home/projects/github-uvwz3x/test-projects/vite-project/node_modules/vitest-link-reproduction/dist/vitest-link-reproduction.js +164ms
vite:resolve-details [url] /node_modules/vitest-link-reproduction/dist/vitest-link-reproduction.js -> /home/projects/github-uvwz3x/test-projects/vite-project/node_modules/vitest-link-reproduction/dist/vitest-link-reproduction.js +1ms
vite:resolve-details [package entry] @mui/base -> /home/projects/github-uvwz3x/test-projects/vite-project/node_modules/@mui/base/node/index.js +1ms
vite:resolve-details [package entry] react -> /home/projects/github-uvwz3x/test-projects/vite-project/node_modules/react/index.js +1ms |
Sadly that setup fails for me: ArloL/vitest-link-reproduction#80 |
still have this issue, when using |
Describe the bug
Thanks so much for creating such wonderful tooling :)
I believe I have found a bug and hope I can describe it well enough here:
file:
resolution and the tests pass ✅link:
resolution and the tests fail with this error message ❌:From my understanding there should be no difference between these two scenarios and the tests should pass. Please let me know if I can provide more info to make it clearer :)
Reproduction
https://github.com/ArloL/vitest-link-reproduction
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: