Skip to content

Commit 50cb5a6

Browse files
Ignore the .rnrepo-cache directory within the Metro config (#4262)
## Description This prevents Metro from crashing with an `Invariant Violation` when internal scripts dynamically recreate this directory or replace it with a symlink during the `expo prebuild` process in example apps. ``` <>gesture-handler/apps/expo-example/node_modules/@expo/cli/build/src/utils/errors.js:130 throw error; ^ Invariant Violation: Detected addition or modification of file node_modules/react-native-screens/.rnrepo-cache/Current, but it is tracked as a non-empty directory at invariant (<>gesture-handler/apps/expo-example/node_modules/invariant/invariant.js:40:15) at TreeFS.addOrModify (<>gesture-handler/apps/expo-example/node_modules/@expo/metro-file-map/build/lib/TreeFS.js:386:41) at Timeout.emitChange [as _onTimeout] (<>gesture-handler/apps/expo-example/node_modules/@expo/metro-file-map/build/index.js:580:32) at listOnTimeout (node:internal/timers:588:17) at process.processTimers (node:internal/timers:523:7) { framesToPop: 1 } ``` ## Test plan 1. Without commit ``` git clone https://github.com/software-mansion/react-native-gesture-handler cd react-native-gesture-handler yarn install cd apps/expo-example yarn start # new terminal (2) cd react-native-gesture-handler/apps/expo-example yarn ios # Metro crashes in the first terminal with the Invariant Violation shown above. ``` 2. With commit ``` git clone https://github.com/software-mansion/react-native-gesture-handler cd react-native-gesture-handler yarn install cd apps/expo-example yarn start # new terminal (2) cd react-native-gesture-handler/apps/expo-example yarn ios # Metro runs normally and no error is thrown in the first terminal ```
1 parent 5d8102b commit 50cb5a6

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

apps/expo-example/metro.config.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ config.resolver.nodeModulesPaths = [
2222
path.resolve(monorepoRoot, 'node_modules'),
2323
];
2424

25-
config.resolver.blacklistRE = exclusionList(
26-
[monorepoRoot, commonAppRoot].flatMap((root) =>
27-
modulesBlacklist.map(
28-
(m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
29-
)
25+
const monorepoExclusions = [monorepoRoot, commonAppRoot].flatMap((root) =>
26+
modulesBlacklist.map(
27+
(m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
3028
)
3129
);
3230

31+
// Concat arrays before passing to exclusionList to prevent runtime crash
32+
config.resolver.blacklistRE = exclusionList(
33+
monorepoExclusions.concat([
34+
// Regex [\/\\] ensures cross-platform compatibility (macOS/Linux/Windows)
35+
/.*[\/\\]\.rnrepo-cache[\/\\].*/
36+
])
37+
);
38+
3339
config.transformer.getTransformOptions = async () => ({
3440
transform: {
3541
experimentalImportSupport: false,

0 commit comments

Comments
 (0)