@@ -9,13 +9,23 @@ const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config');
99const fs = require ( 'fs' ) ;
1010const path = require ( 'path' ) ;
1111
12- const rnwPath = fs . realpathSync (
12+ // On Windows, require.resolve through symlinks (e.g. yarn workspace links) can
13+ // return paths with a different drive letter case than process.cwd(). Metro's
14+ // file system lookup is case-sensitive, so we normalize to match cwd.
15+ function normalizePathDrive ( p ) {
16+ if ( process . platform === 'win32' && p . length >= 2 && p [ 1 ] === ':' ) {
17+ return process . cwd ( ) [ 0 ] + p . slice ( 1 ) ;
18+ }
19+ return p ;
20+ }
21+
22+ const rnwPath = normalizePathDrive ( fs . realpathSync (
1323 path . dirname ( require . resolve ( 'react-native-windows/package.json' ) ) ,
14- ) ;
24+ ) ) ;
1525
16- const rnwTesterPath = fs . realpathSync (
26+ const rnwTesterPath = normalizePathDrive ( fs . realpathSync (
1727 path . dirname ( require . resolve ( '@react-native-windows/tester/package.json' ) ) ,
18- ) ;
28+ ) ) ;
1929
2030const devPackages = {
2131 'react-native' : path . normalize ( rnwPath ) ,
@@ -144,8 +154,25 @@ function tryResolveDevRelativeImport(
144154 return null ;
145155}
146156
147- module . exports = makeMetroConfig ( {
157+ const baseConfig = makeMetroConfig ( {
148158 resolver : {
149159 resolveRequest : devResolveRequest ,
150160 } ,
151161} ) ;
162+
163+ // The getModulesRunBeforeMainModule paths (from @rnx-kit/metro-config) may have
164+ // wrong drive letter case on Windows due to require.resolve through symlinks.
165+ // Metro compares these paths via strict equality against module paths in the
166+ // bundle graph, so the case must match exactly.
167+ const originalGetModulesRunBeforeMainModule =
168+ baseConfig . serializer . getModulesRunBeforeMainModule ;
169+ baseConfig . serializer = {
170+ ...baseConfig . serializer ,
171+ getModulesRunBeforeMainModule : ( ...args ) => {
172+ return originalGetModulesRunBeforeMainModule ( ...args ) . map ( p =>
173+ normalizePathDrive ( fs . realpathSync ( p ) ) ,
174+ ) ;
175+ } ,
176+ } ;
177+
178+ module . exports = baseConfig ;
0 commit comments