Closed fdw closed 9 months ago
My personal opinion is that it's better to know that current lockfile is in a bad state, but for compatibility I will to it here too.
I'm sorry, what do you mean with "that current lockfile is in a bad state"? Are you talking about package-lock.json
or something else?
Maybe it's my fault after all 🙈
What I mean is that your node_modules contains two version of React, either because some lib use a dependency on react instead of peerDependency, or because of not sync react and react-dom, or maybe something else. It's not your fault, can easily happen when doing an npm install on a project with an existing lockfile.
IMO the good solution there is to inspect the lockfile, see the two version installed and see what trigger it and then update the package.json to ensure that only one version of react(-dom) is needed
I've just checked npm ls react
and npm ls react-dom
, and while both show that a lot of packages depend on them, it's only ever version 18.2.0
:/
I think I've once read that the problem might occur because vite uses esm, but some modules might use cjs, and thus react will be loaded twice - can that happen? Would that be precented by dedupe
?
react still doesn't ship esm format (and if it did Vite should always enforce using the ESM one).
I'm curious on how you ended with this warning. The most probable in that case is a bug in the pre-bundling of deps with late discovered deps. And I will be surprised that dedupe help in that case, or maybe I'm wrong on how dedupe works in Vite
Thank you so much for your help, that clears things up a lot 🙂
Could it be a problem if one of the dependencies supports esm and depends on React?
Also, I'll try to build a mini test-case, if/when I have time... but that might be a bit...
Did you found the root cause of the duplicate react module?
As I'm rethinking it now, React 17 did some internal changes to allow to have multiple react version on the same page (not in the same tree i think) so I would not force people to one version actually.
Unfortunately, I couldn't find the problem :(
Feel free to close this issue. If I can remember/find something, I'll just comment again.
Thanks for your time!
I've been trying to run a small project with
vite-plugin-react-swc
using MUI, but it always errored out with:Adding
resolve: {dedupe: ["react", "react-dom"]}
to vite's config solves the problem.vite-plugin-react
seems to automatically do this, so maybe it would be a good idea for this one, too?