Skip to content

Commit 3665521

Browse files
committed
Fix JS issues in Node.js 24.x
1 parent d711a3b commit 3665521

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

packages/playground/metro.config.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config');
99
const fs = require('fs');
1010
const 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 must normalize to match.
15+
function normalizePathDrive(p) {
16+
if (process.platform === 'win32' && p.length >= 2 && p[1] === ':') {
17+
return p[0].toUpperCase() + 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

2030
const 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;

vnext/PropertySheets/Codegen.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<PropertyGroup>
99
<RunCodegenWindows Condition="'$(RunCodegenWindows)' == ''">true</RunCodegenWindows>
10-
<CodegenCommand Condition="'$(CodegenCommand)' == ''">npx --yes @react-native-community/cli codegen-windows</CodegenCommand>
10+
<CodegenCommand Condition="'$(CodegenCommand)' == ''">npx --yes --no-workspaces @react-native-community/cli codegen-windows</CodegenCommand>
1111
<CodegenCommandWorkingDir Condition="'$(CodegenCommandWorkingDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(ProjectDir), 'package.json'))</CodegenCommandWorkingDir>
1212
<CodegenCommandArgs Condition="'$(CodegenCommandArgs)' == ''">--logging</CodegenCommandArgs>
1313
</PropertyGroup>

0 commit comments

Comments
 (0)