File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed
packages/react-router-dev/vite Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change
1
+ export function hasDependency ( {
2
+ name,
3
+ rootDirectory,
4
+ } : {
5
+ name : string ;
6
+ rootDirectory : string ;
7
+ } ) {
8
+ try {
9
+ return Boolean ( require . resolve ( name , { paths : [ rootDirectory ] } ) ) ;
10
+ } catch ( err ) {
11
+ return false ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ import { resolveFileUrl } from "./resolve-file-url";
58
58
import { combineURLs } from "./combine-urls" ;
59
59
import { removeExports } from "./remove-exports" ;
60
60
import { ssrExternals } from "./ssr-externals" ;
61
+ import { hasDependency } from "./has-dependency" ;
61
62
import {
62
63
type RouteChunkName ,
63
64
type RouteChunkExportName ,
@@ -819,14 +820,6 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
819
820
return JSON . parse ( manifestContents ) as Vite . Manifest ;
820
821
} ;
821
822
822
- let hasDependency = ( name : string ) => {
823
- try {
824
- return Boolean ( require . resolve ( name , { paths : [ ctx . rootDirectory ] } ) ) ;
825
- } catch ( err ) {
826
- return false ;
827
- }
828
- } ;
829
-
830
823
let getViteManifestAssetPaths = (
831
824
viteManifest : Vite . Manifest ,
832
825
) : Set < string > => {
@@ -1293,7 +1286,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1293
1286
"react-router" ,
1294
1287
"react-router/dom" ,
1295
1288
// Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'"
1296
- ...( hasDependency ( "react-router-dom" )
1289
+ ...( hasDependency ( {
1290
+ name : "react-router-dom" ,
1291
+ rootDirectory : ctx . rootDirectory ,
1292
+ } )
1297
1293
? [ "react-router-dom" ]
1298
1294
: [ ] ) ,
1299
1295
] ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
type ResolvedReactRouterConfig ,
13
13
createConfigLoader ,
14
14
} from "../../config/config" ;
15
+ import { hasDependency } from "../has-dependency" ;
15
16
import { createVirtualRouteConfig } from "./virtual-route-config" ;
16
17
import {
17
18
transformVirtualRouteModules ,
@@ -69,7 +70,9 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
69
70
// You must render this element inside a <Remix> element`.
70
71
"react-router" ,
71
72
"react-router/dom" ,
72
- "react-router-dom" ,
73
+ ...( hasDependency ( { name : "react-router-dom" , rootDirectory } )
74
+ ? [ "react-router-dom" ]
75
+ : [ ] ) ,
73
76
] ,
74
77
} ,
75
78
optimizeDeps : {
@@ -85,6 +88,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
85
88
"react/jsx-dev-runtime" ,
86
89
"react-dom" ,
87
90
"react-dom/client" ,
91
+ "react-router/internal/react-server-client" ,
88
92
] ,
89
93
} ,
90
94
esbuild : {
You can’t perform that action at this time.
0 commit comments