Skip to content

Commit a039172

Browse files
committed
update metro.config to ignore parent node_modules
1 parent 706818f commit a039172

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/metro.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ const { getDefaultConfig } = require('expo/metro-config');
22
// const exclusionList = require('metro-config/src/defaults/exclusionList');
33
const path = require('path');
44

5+
// Helper to safely embed a path in RegExp
6+
const escapeRegExp = (s) => s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
7+
58
const projectRoot = __dirname;
69
const workspaceRoot = path.resolve(__dirname, '..');
10+
const parentNodeModules = path.join(workspaceRoot, 'node_modules');
711

812
const config = getDefaultConfig(projectRoot);
913

@@ -13,11 +17,12 @@ config.resolver = {
1317
...config.resolver,
1418
nodeModulesPaths: [
1519
path.join(projectRoot, 'node_modules'),
16-
path.join(workspaceRoot, 'node_modules'),
1720
],
1821

1922
// Ignore common explosion points
2023
blockList: [
24+
new RegExp(`^${escapeRegExp(parentNodeModules)}[/\\\\].*`),
25+
2126
// avoid triply nested node_modules to resolve issue with using a local copy of the module
2227
/.*\/node_modules\/.*\/node_modules\/.*\/node_modules\/.*/,
2328

0 commit comments

Comments
 (0)