@@ -738,6 +738,21 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
738
738
viteConfigEnv = _viteConfigEnv ;
739
739
viteCommand = viteConfigEnv . command ;
740
740
741
+ // This is a compatibility layer for Vite 5. Default conditions were
742
+ // automatically added to any custom conditions in Vite 5, but Vite 6
743
+ // removed this behavior. Instead, the default conditions are overridden
744
+ // by any custom conditions. If we wish to retain the default
745
+ // conditions, we need to manually merge them using the provided default
746
+ // conditions arrays exported from Vite. In Vite 5, these default
747
+ // conditions arrays do not exist.
748
+ // https://vite.dev/guide/migration.html#default-value-for-resolve-conditions
749
+ let viteClientConditions : string [ ] = [
750
+ ...( vite . defaultClientConditions ?? [ ] ) ,
751
+ ] ;
752
+ let viteServerConditions : string [ ] = [
753
+ ...( vite . defaultServerConditions ?? [ ] ) ,
754
+ ] ;
755
+
741
756
logger = vite . createLogger ( viteUserConfig . logLevel , {
742
757
prefix : "[react-router]" ,
743
758
} ) ;
@@ -804,9 +819,14 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
804
819
ssr : {
805
820
external : ssrExternals ,
806
821
resolve : {
807
- conditions : viteCommand === "build" ? [ ] : [ "development" ] ,
822
+ conditions :
823
+ viteCommand === "build"
824
+ ? viteServerConditions
825
+ : [ "development" , ...viteServerConditions ] ,
808
826
externalConditions :
809
- viteCommand === "build" ? [ ] : [ "development" ] ,
827
+ viteCommand === "build"
828
+ ? viteServerConditions
829
+ : [ "development" , ...viteServerConditions ] ,
810
830
} ,
811
831
} ,
812
832
optimizeDeps : {
@@ -853,7 +873,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
853
873
"react-router/dom" ,
854
874
"react-router-dom" ,
855
875
] ,
856
- conditions : viteCommand === "build" ? [ ] : [ "development" ] ,
876
+ conditions :
877
+ viteCommand === "build"
878
+ ? viteClientConditions
879
+ : [ "development" , ...viteClientConditions ] ,
857
880
} ,
858
881
base : viteUserConfig . base ,
859
882
0 commit comments