-
-
Notifications
You must be signed in to change notification settings - Fork 622
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 3.1.5 breaks Jotai babel plugins #1475
Comments
The repo is created with the Vite typescript react template. Then just vite.config.ts was modified to look like here: https://jotai.org/docs/guides/vite |
Hmm looking at the exports in jotais package.json I am wondering why Vite loads the .js and not the .mjs file (in which the import syntax is legal).
|
Patching package.json and changing the "module" entries of debug-label and react-refresh to point to the .mjs files makes the error go away. This is not a solution of course. Something in Vite 3.1.5 changed the exports loading logic it seems. |
Looking at the changes in Vite from 3.1.4 to 3.1.5 this commit changed the module resolving behaviour: |
(Hmmm, I follow this pattern in almost all of my libs.) |
tryNodeResolve returns the .js path, not the .mjs path. |
I traced execution now into a third party-module called es-module-lexer which Vite seems to use since 3.1.5 for analysing imports/exports etc.. |
I traced into es-module-lexer now and he bailed out at conditional export "module" which is wrong. I am not 100% sure but I think "module" is not a built-in Node conditional export condition. I also didn't find it in the Typescript documentation. See: https://nodejs.org/api/packages.html#conditional-exports Should it probably be "require"? But the file "module" points to contains import statements. |
Ah I see, "module" is a custom conditional export for webpack/rollup/wmr. |
It's an unofficial/conventional field by community. Same for "types". Related PRs: #679 #583 c6d54f7 |
Ok, I will make a bug report in the Vite repo and backlink to this discussion. Lets see what happens :) |
Why would you expect webpack/rollup/wmr to use the field, but want Vite to ignore it?
From which community? I'm curious where this originated
Helps how? What's the point in having two exactly equivalent files with different file extensions? |
I assume it's originated by webpack and some other bundlers follow it. Currently, they are the same file, but in the future they can be different. Like, if old bundlers don't understand something of native ESM. (But, before reaching to that point, we may drop support of old bundlers, which means to remove "module" field entirely.) |
It is a deprecated convention, meant for tools that do not understand the .mjs file extension. More context: pmndrs/jotai#1475 (comment)
Maybe can use https://github.com/ahungrynoob/jotai-ts-transformer. It is a typescript transformer. |
This problem was fixed already upstream in Vite. @dai-shi: Bug can be closed :) |
Using the debug label and react refresh plugins does not work anymore starting with Vite 3.1.5.
vite dev chokes with the following error:
Reverting to Vite 3.1.4 fixes the error.
For reproduction use this repo: https://github.com/gunters63/jotei-vite-import-error
pnpm install and pnpm dev should be enough.
I am not sure this is an upstream error in Vite, they had a similar problem which was supposed to be fixed in 3.16.
This problem here persists with 3.1.6 and 3.17.
The text was updated successfully, but these errors were encountered: