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";
5858import { combineURLs } from "./combine-urls" ;
5959import { removeExports } from "./remove-exports" ;
6060import { ssrExternals } from "./ssr-externals" ;
61+ import { hasDependency } from "./has-dependency" ;
6162import {
6263 type RouteChunkName ,
6364 type RouteChunkExportName ,
@@ -819,14 +820,6 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
819820 return JSON . parse ( manifestContents ) as Vite . Manifest ;
820821 } ;
821822
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-
830823 let getViteManifestAssetPaths = (
831824 viteManifest : Vite . Manifest ,
832825 ) : Set < string > => {
@@ -1293,7 +1286,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
12931286 "react-router" ,
12941287 "react-router/dom" ,
12951288 // 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+ } )
12971293 ? [ "react-router-dom" ]
12981294 : [ ] ) ,
12991295 ] ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 type ResolvedReactRouterConfig ,
1313 createConfigLoader ,
1414} from "../../config/config" ;
15+ import { hasDependency } from "../has-dependency" ;
1516import { createVirtualRouteConfig } from "./virtual-route-config" ;
1617import {
1718 transformVirtualRouteModules ,
@@ -69,7 +70,9 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
6970 // You must render this element inside a <Remix> element`.
7071 "react-router" ,
7172 "react-router/dom" ,
72- "react-router-dom" ,
73+ ...( hasDependency ( { name : "react-router-dom" , rootDirectory } )
74+ ? [ "react-router-dom" ]
75+ : [ ] ) ,
7376 ] ,
7477 } ,
7578 optimizeDeps : {
@@ -85,6 +88,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
8588 "react/jsx-dev-runtime" ,
8689 "react-dom" ,
8790 "react-dom/client" ,
91+ "react-router/internal/react-server-client" ,
8892 ] ,
8993 } ,
9094 esbuild : {
You can’t perform that action at this time.
0 commit comments