WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/react-start/src/plugin/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ export function tanstackStart(
: ['@tanstack/react-router', '@tanstack/react-router-devtools'],
},
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)
// Vitest uses Vite's config, but `optimizeDeps` (pre-bundling) causes conflicts
// when workspace packages (transformed by Vitest) interact with external packages (Node-native).
// This is especially problematic for React, leading to "Invalid hook call" errors due to
// duplicate React instances (one pre-bundled ESM, one native CJS).
// We disable this enforced optimization when running in Vitest to allow standard resolution.
process.env.VITEST !== 'true' &&
(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))
? {
// As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both.
exclude: [
Expand Down
Loading