From e8a923f870a7f13691da51f38094983d69c7488e Mon Sep 17 00:00:00 2001 From: Tiger3018 Date: Wed, 16 Oct 2024 12:46:11 +0200 Subject: [PATCH] fix: add `react-dom` in `optimizeOps` to handle CJS script. (#375) --- packages/plugin-react/src/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index f5c1e3c6..b8f54998 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -269,10 +269,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] { }, } - // We can't add `react-dom` because the dependency is `react-dom/client` - // for React 18 while it's `react-dom` for React 17. We'd need to detect - // what React version the user has installed. - const dependencies = ['react', jsxImportDevRuntime, jsxImportRuntime] + const dependencies = [ + 'react', + 'react-dom', + jsxImportDevRuntime, + jsxImportRuntime, + ] const staticBabelPlugins = typeof opts.babel === 'object' ? opts.babel?.plugins ?? [] : [] const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins)