diff --git a/packages/react-start/src/plugin/vite.ts b/packages/react-start/src/plugin/vite.ts index 4288e9dce02..9f194a7945c 100644 --- a/packages/react-start/src/plugin/vite.ts +++ b/packages/react-start/src/plugin/vite.ts @@ -46,30 +46,31 @@ export function tanstackStart( }, optimizeDeps: environmentName === VITE_ENVIRONMENT_NAMES.client || - (environmentName === VITE_ENVIRONMENT_NAMES.server && - // This indicates that the server environment has opted in to dependency optimization - options.optimizeDeps?.noDiscovery === false) + (environmentName === VITE_ENVIRONMENT_NAMES.server && + // This indicates that the server environment has opted in to dependency optimization + options.optimizeDeps?.noDiscovery === false) ? { - // As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both. - exclude: [ - '@tanstack/react-start', - '@tanstack/react-router', - '@tanstack/react-router-devtools', - '@tanstack/start-static-server-functions', - ], - include: [ - 'react', - 'react/jsx-runtime', - 'react/jsx-dev-runtime', - 'react-dom', - ...(environmentName === VITE_ENVIRONMENT_NAMES.client - ? ['react-dom/client'] - : ['react-dom/server']), - // `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS. - // It therefore needs to be included so that it is converted to ESM. - '@tanstack/react-router > @tanstack/react-store', - ], - } + // As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both. + exclude: [ + '@tanstack/react-start', + '@tanstack/react-router', + '@tanstack/react-router-devtools', + '@tanstack/start-static-server-functions', + ], + include: [ + 'react', + 'react/jsx-runtime', + 'react/jsx-dev-runtime', + 'react-dom', + ...(environmentName === VITE_ENVIRONMENT_NAMES.client + ? ['react-dom/client'] + : ['react-dom/server']), + // `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS. + // It therefore needs to be included so that it is converted to ESM. + '@tanstack/react-router > @tanstack/react-store', + ...(options.optimizeDeps?.exclude?.find(x => x === '@tanstack/react-form') ? ['@tanstack/react-form > @tanstack/react-store'] : []), + ], + } : undefined, } },