1+ const { getDefaultConfig } = require ( 'expo/metro-config' ) ;
2+ // Use the exported private path so Node respects the package "exports" map
3+ // (requiring `metro-config/src/...` can fail under newer Node/npm due to exports restrictions).
4+ const exclusionList = require ( 'metro-config/private/defaults/exclusionList' ) ;
5+ const path = require ( 'path' ) ;
6+
7+ /**
8+ * Custom Metro configuration for the example app.
9+ *
10+ * Important: We intentionally DO NOT include the parent (repo root) node_modules
11+ * path in nodeModulesPaths anymore because the root devDependencies use a newer
12+ * React / React Native (0.81.x) version than the example (Expo SDK 51 with
13+ * React Native 0.74.x). Allowing Metro to resolve modules from the root caused
14+ * it to pick up the newer react-native implementation which currently ships
15+ * TypeScript-only syntax (e.g. `} as ReactNativePublicAPI;`) that the example
16+ * Babel preset (SDK 51) was not configured to parse, triggering a syntax error.
17+ *
18+ * By constraining resolution to the example's own node_modules we guarantee the
19+ * correct (0.74.x) React Native code path is bundled. We still alias the
20+ * library source so changes to the `lib` folder are reflected live.
21+ */
22+ const config = getDefaultConfig ( __dirname ) ;
23+
24+ // Only watch the library source for live development to avoid pulling in root node_modules versions.
25+ config . watchFolders = [ path . resolve ( __dirname , '..' , 'lib' ) ] ;
26+
27+ // Allow dependencies from both local and root node_modules (library dev deps) while we block root RN.
28+ config . resolver . nodeModulesPaths = [
29+ path . resolve ( __dirname , 'node_modules' ) ,
30+ path . resolve ( __dirname , '..' , 'node_modules' ) ,
31+ ] ;
32+
33+ // Alias the library to its source entry to ensure it resolves correctly without needing the root node_modules.
34+ config . resolver . alias = {
35+ 'react-native-big-list' : path . resolve ( __dirname , '..' , 'lib' , 'index.js' ) ,
36+ // Force React Native to resolve to the example's version
37+ 'react-native' : path . resolve ( __dirname , 'node_modules' , 'react-native' ) ,
38+ } ;
39+
40+ // Block the root react-native (0.81.x) to avoid TS-only syntax errors
41+ const rootReactNativePath = path . resolve ( __dirname , '..' , 'node_modules' , 'react-native' ) ;
42+ config . resolver . blockList = exclusionList ( [
43+ new RegExp ( `${ rootReactNativePath . replace ( / [ - / \\ ^ $ * + ? . ( ) | [ \] { } ] / g, r => `\\${ r } ` ) } .*` ) ,
44+ ] ) ;
45+
46+ // Remove any explicit extraNodeModules overrides (not needed with isolated resolution).
47+ delete config . resolver . extraNodeModules ;
48+
49+ module . exports = config ;
0 commit comments