Skip to content

Commit d154511

Browse files
authored
fix(windows): JavaScriptMainModuleName is deprecated (#347)
`JavaScriptMainModuleName` was deprecated in 0.64, and removed in microsoft/react-native-windows@22e1206.
1 parent 23ee720 commit d154511

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

example/metro.config.windows.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
*/
77
const fs = require("fs");
88
const path = require("path");
9-
const blacklist = require("metro-config/src/defaults/blacklist");
9+
10+
const exclusionList = (() => {
11+
try {
12+
return require("metro-config/src/defaults/exclusionList");
13+
} catch (_) {
14+
// `blacklist` was renamed to `exclusionList` in 0.60
15+
return require("metro-config/src/defaults/blacklist");
16+
}
17+
})();
1018

1119
const rnPath = fs.realpathSync(
1220
path.resolve(require.resolve("react-native/package.json"))
@@ -15,31 +23,30 @@ const rnwPath = fs.realpathSync(
1523
path.resolve(require.resolve("react-native-windows/package.json"))
1624
);
1725

26+
const blockList = exclusionList([
27+
// Since there are multiple copies of react-native, we need to ensure that
28+
// Metro only sees one of them. This should go when haste-map is removed.
29+
new RegExp(`${(path.resolve(rnPath) + path.sep).replace(/[/\\]/g, "/")}.*`),
30+
31+
// This stops "react-native run-windows" from causing the metro server to
32+
// crash if its already running
33+
new RegExp(`${path.resolve(__dirname, "windows").replace(/[/\\]/g, "/")}.*`),
34+
35+
// Workaround for `EBUSY: resource busy or locked, open
36+
// '~\msbuild.ProjectImports.zip'` when building with `yarn windows --release`
37+
/.*\.ProjectImports\.zip/,
38+
]);
39+
1840
module.exports = {
1941
resolver: {
2042
extraNodeModules: {
2143
// Redirect react-native to react-native-windows
2244
"react-native": rnwPath,
2345
"react-native-windows": rnwPath,
2446
},
25-
// Include the macos platform in addition to the defaults because the fork includes macos, but doesn't declare it
26-
platforms: ["ios", "android", "windesktop", "windows", "web", "macos"],
27-
// Since there are multiple copies of react-native, we need to ensure that metro only sees one of them
28-
// This should go in RN 0.61 when haste is removed
29-
blacklistRE: blacklist([
30-
new RegExp(
31-
`${(path.resolve(rnPath) + path.sep).replace(/[/\\]/g, "/")}.*`
32-
),
33-
34-
// This stops "react-native run-windows" from causing the metro server to crash if its already running
35-
new RegExp(
36-
`${path.resolve(__dirname, "windows").replace(/[/\\]/g, "/")}.*`
37-
),
38-
39-
// Workaround for `EBUSY: resource busy or locked, open '~\msbuild.ProjectImports.zip'`
40-
// when building with `yarn windows --release`
41-
/.*\.ProjectImports\.zip/,
42-
]),
47+
platforms: ["windesktop", "windows"],
48+
blacklistRE: blockList,
49+
blockList,
4350
},
4451
transformer: {
4552
getTransformOptions: async () => ({

windows/ReactTestApp/ReactInstance.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ void ReactInstance::LoadJSBundleFrom(JSBundleSource source)
9191
auto instanceSettings = reactNativeHost_.InstanceSettings();
9292
switch (source) {
9393
case JSBundleSource::DevServer:
94+
#if REACT_NATIVE_VERSION < 6400
9495
instanceSettings.JavaScriptMainModuleName(L"index");
9596
instanceSettings.JavaScriptBundleFile(L"");
97+
#else
98+
instanceSettings.JavaScriptBundleFile(L"index");
99+
#endif
96100
break;
97101
case JSBundleSource::Embedded:
98102
instanceSettings.JavaScriptBundleFile(winrt::to_hstring(GetBundleName()));

0 commit comments

Comments
 (0)