When using this project within a monorepo or a library development environment (like the provided example folder), you must configure Metro to prevent multiple versions of peerDependencies from being loaded. This is achieved by:
- Blacklisting the
node_modules located at the project root to prevent Metro from resolving them. - Aliasing those same modules to the specific versions installed within the local
example/node_modules using extraNodeModules.
This ensures that the application uses the exact versions of peer dependencies intended for the example/app context, avoiding conflicts.
const config = {
...defaultConfig,
projectRoot: __dirname,
watchFolders: [root],
resolver: {
...defaultConfig.resolver,
// 1. Block peerDependencies at the root
blacklistRE: exclusionList(
modules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),
// 2. Alias them to the local node_modules
extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
},
};