@@ -3462,10 +3462,6 @@ export async function getEnvironmentOptionsResolvers(
3462
3462
`file:///${ path . join ( packageRoot , "module-sync-enabled/index.mjs" ) } `
3463
3463
) ;
3464
3464
let vite = getVite ( ) ;
3465
- let viteServerConditions : string [ ] = [
3466
- ...( vite . defaultServerConditions ?? [ ] ) ,
3467
- ...( moduleSyncEnabled ? [ "module-sync" ] : [ ] ) ,
3468
- ] ;
3469
3465
3470
3466
function getBaseOptions ( {
3471
3467
viteUserConfig,
@@ -3521,10 +3517,35 @@ export async function getEnvironmentOptionsResolvers(
3521
3517
} : {
3522
3518
viteUserConfig : Vite . UserConfig ;
3523
3519
} ) : 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
+ ] ;
3528
3549
3529
3550
return mergeEnvironmentOptions ( getBaseOptions ( { viteUserConfig } ) , {
3530
3551
resolve : {
@@ -3533,8 +3554,8 @@ export async function getEnvironmentOptionsResolvers(
3533
3554
ctx . reactRouterConfig . future . unstable_viteEnvironmentApi
3534
3555
? undefined
3535
3556
: ssrExternals ,
3536
- conditions,
3537
- externalConditions : conditions ,
3557
+ conditions : [ ... baseConditions , ... maybeDefaultServerConditions ] ,
3558
+ externalConditions : [ ... baseConditions , ... defaultExternalConditions ] ,
3538
3559
} ,
3539
3560
build : {
3540
3561
// We move SSR-only assets to client assets. Note that the
0 commit comments