You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I'm using this library in my Vite-based app (using template react-ts) and everything works. It's using the "dist/index.esm.js" file from that library.
However, now I tried to add Vitest and it doesn't work anymore because Vitest is using "dist/index.js". So there seems to be a difference in the actual file which is loaded.
Maybe I'm missing some config options?
One of the goals of Vitest is to have the same pipeline for both prod and test which seems to be not the case here.
(my initial problem was that I have a PNPM based monorepo setup were I'm having a react library and an example react project. Before, I was using create-react-app which had the issue of React-Hooks violation due to duplicated react versions. By switching to Vite, I was able to fix that (due to auto dedupe in the react-plugin I assume) which is great. However, in my Vitest-based tests I still had the error and I was able to debug to the point that Vitest is using the file from "main" while Vite is using the file from "module")
But I would not recommend using it, since it is meant to be used by bundlers. If you want to publish actual ESM file that Node will understand, you need to use exports field in your package.json. Here is more info: https://github.com/sheremet-va/dual-packaging
Describe the bug
I have a library with this package.json:
Now I'm using this library in my Vite-based app (using template react-ts) and everything works. It's using the "dist/index.esm.js" file from that library.
However, now I tried to add Vitest and it doesn't work anymore because Vitest is using "dist/index.js". So there seems to be a difference in the actual file which is loaded.
Maybe I'm missing some config options?
One of the goals of Vitest is to have the same pipeline for both prod and test which seems to be not the case here.
(my initial problem was that I have a PNPM based monorepo setup were I'm having a react library and an example react project. Before, I was using create-react-app which had the issue of React-Hooks violation due to duplicated react versions. By switching to Vite, I was able to fix that (due to auto dedupe in the react-plugin I assume) which is great. However, in my Vitest-based tests I still had the error and I was able to debug to the point that Vitest is using the file from "main" while Vite is using the file from "module")
Reproduction
https://github.com/manuel-mauky/repro_vitest_issue_module_resolution
In
my-lib
there is a minimal npm package with these files:In
my-app
is a react app freshly generated withnpm create vite my-app -- --template react-ts
.In
App.tsx
I'm using the helloWorld function:When I start this app, in the browser I see
hello world index.esm.js
.In
App.test.tsx
I'm testing this behavior:but it fails with
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: