fix: add react and react-dom to resolve.dedupe at config#223
fix: add react and react-dom to resolve.dedupe at config#223lazarv wants to merge 1 commit intovitejs:mainfrom
Conversation
|
My plan is to do the opposite and remove the dedupe option from the Babel plugin: vitejs/vite-plugin-react#280 (comment) For me users should always have exactly one version of React installed. Why is this not the case for you? |
|
My issue is that Vite uses if (dedupe?.includes(pkgId)) {
basedir = root
} else if (
importer &&
path.isAbsolute(importer) &&
// css processing appends `*` for importer
(importer[importer.length - 1] === '*' || fs.existsSync(cleanUrl(importer)))
) {
basedir = path.dirname(importer)
} else {
basedir = root
}With a root at I had a lot of resolution issues because React is not installed in the consumer project, so I do a lot of resolution workarounds to achieve what's necessary for the framework to work like a CLI tool too on any given React component file. Sorry @ArnaudBarre I missed the existing PR at @vitejs/plugin-react removing |
Adds "react" and "react-dom" to
resolve.dedupein theconfighook. @vitejs/plugin-react does the same at https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L289-L291.For some context, the missing dedupe of these React packages caused issues in my own React meta-framework (@lazarv/react-server) when adding support for @vitejs/plugin-react-swc. Using Vite Environment API it was not able to resolve "react/jsx-dev-runtime". I usually work on the framework in a pnpm workspace and the framework also provides it's own strict experimental React version.