From bc4a627efe234a00b61f96eeb0090743643c2e3d Mon Sep 17 00:00:00 2001 From: Rom Date: Fri, 19 Aug 2022 14:57:06 +0200 Subject: [PATCH] fix: add `react` to `optimizeDeps` (#9056) --- packages/plugin-react/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index f1adf81510bcef..5a82b0a2a6cd0e 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -406,7 +406,10 @@ export default function viteReact(opts: Options = {}): PluginOption[] { config() { return { optimizeDeps: { - include: [reactJsxRuntimeId, reactJsxDevRuntimeId] + // 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. + include: [reactJsxRuntimeId, reactJsxDevRuntimeId, 'react'] } } },