@@ -3462,10 +3462,6 @@ export async function getEnvironmentOptionsResolvers(
34623462 `file:///${ path . join ( packageRoot , "module-sync-enabled/index.mjs" ) } `
34633463 ) ;
34643464 let vite = getVite ( ) ;
3465- let viteServerConditions : string [ ] = [
3466- ...( vite . defaultServerConditions ?? [ ] ) ,
3467- ...( moduleSyncEnabled ? [ "module-sync" ] : [ ] ) ,
3468- ] ;
34693465
34703466 function getBaseOptions ( {
34713467 viteUserConfig,
@@ -3521,10 +3517,35 @@ export async function getEnvironmentOptionsResolvers(
35213517 } : {
35223518 viteUserConfig : Vite . UserConfig ;
35233519 } ) : EnvironmentOptions {
3524- let conditions =
3525- viteCommand === "build"
3526- ? viteServerConditions
3527- : [ "development" , ...viteServerConditions ] ;
3520+ // We're using the module-sync condition, but Vite
3521+ // doesn't support it by default.
3522+ // See https://github.com/vitest-dev/vitest/issues/7692
3523+ let maybeModuleSyncConditions : string [ ] = [
3524+ ...( moduleSyncEnabled ? [ "module-sync" ] : [ ] ) ,
3525+ ] ;
3526+
3527+ let maybeDevelopmentConditions =
3528+ viteCommand === "build" ? [ ] : [ "development" ] ;
3529+
3530+ // This is a compatibility layer for Vite 5. Default conditions were
3531+ // automatically added to any custom conditions in Vite 5, but Vite 6
3532+ // removed this behavior. Instead, the default conditions are overridden
3533+ // by any custom conditions. If we wish to retain the default
3534+ // conditions, we need to manually merge them using the provided default
3535+ // conditions arrays exported from Vite. In Vite 5, these default
3536+ // conditions arrays do not exist.
3537+ // https://vite.dev/guide/migration.html#default-value-for-resolve-conditions
3538+ let maybeDefaultServerConditions = vite . defaultServerConditions || [ ] ;
3539+
3540+ // There is no helpful export with the default external conditions (see
3541+ // https://github.com/vitejs/vite/pull/20279 for more details). So, for now,
3542+ // we are hardcording the default here.
3543+ let defaultExternalConditions = [ "node" ] ;
3544+
3545+ let baseConditions = [
3546+ ...maybeDevelopmentConditions ,
3547+ ...maybeModuleSyncConditions ,
3548+ ] ;
35283549
35293550 return mergeEnvironmentOptions ( getBaseOptions ( { viteUserConfig } ) , {
35303551 resolve : {
@@ -3533,8 +3554,8 @@ export async function getEnvironmentOptionsResolvers(
35333554 ctx . reactRouterConfig . future . unstable_viteEnvironmentApi
35343555 ? undefined
35353556 : ssrExternals ,
3536- conditions,
3537- externalConditions : conditions ,
3557+ conditions : [ ... baseConditions , ... maybeDefaultServerConditions ] ,
3558+ externalConditions : [ ... baseConditions , ... defaultExternalConditions ] ,
35383559 } ,
35393560 build : {
35403561 // We move SSR-only assets to client assets. Note that the
0 commit comments