Skip to content

Commit 90fa1a6

Browse files
Fix metro config to always add monorepo root to watchFolders
The previous condition only added watchFolders if the array was empty, but @rnx-kit/metro-config might return a non-empty array. This caused the macOS test app to fail to resolve @React-Native-Node-API packages during bundling. Fixes the UnableToResolveError for @react-native-node-api/node-addon-examples Co-authored-by: Kræn Hansen <mail@kraenhansen.dk>
1 parent f007b25 commit 90fa1a6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

apps/test-app/metro.config.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ const config = makeMetroConfig({
1111
},
1212
});
1313

14-
if (config.watchFolders.length === 0) {
15-
// This patch is needed to locate packages in the monorepo from the MacOS app
16-
// which is intentionally kept outside of the workspaces configuration to prevent
17-
// duplicate react-native version and pollution of the package lock.
18-
const path = require("node:path");
19-
config.watchFolders.push(path.resolve(__dirname, "../.."));
14+
// This patch is needed to locate packages in the monorepo from the MacOS app
15+
// which is intentionally kept outside of the workspaces configuration to prevent
16+
// duplicate react-native version and pollution of the package lock.
17+
const path = require("node:path");
18+
const monorepoRoot = path.resolve(__dirname, "../..");
19+
if (!config.watchFolders) {
20+
config.watchFolders = [];
21+
}
22+
if (!config.watchFolders.includes(monorepoRoot)) {
23+
config.watchFolders.push(monorepoRoot);
2024
}
2125

2226
module.exports = config;

0 commit comments

Comments
 (0)