Skip to content

Commit 33e579d

Browse files
authored
fix(example): resolve react/react-native from the example app (#6)
In this library+example layout, npm auto-installs the library's peerDependencies (expo, react, react-native) at their latest versions into the repo-root node_modules. The example's Metro watches the monorepo root, so codegen could pull the root's newer react-native and fail ("Unable to determine event arguments" in VirtualViewNativeComponent). Pin the react/react-native singletons to the example's own node_modules and block the root copies.
1 parent 8bc3144 commit 33e579d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎example/metro.config.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,20 @@ config.resolver.nodeModulesPaths = [
1515
path.resolve(monorepoRoot, 'node_modules'),
1616
];
1717

18+
// The monorepo root also carries its own (newer) react / react-native, pulled in
19+
// by npm auto-installing the library's peerDependencies. Pin the singletons to the
20+
// example's copies so Metro and React Native codegen never mix versions — mixing
21+
// breaks native component codegen (e.g. "Unable to determine event arguments" in
22+
// VirtualViewNativeComponent).
23+
config.resolver.extraNodeModules = {
24+
react: path.resolve(projectRoot, 'node_modules/react'),
25+
'react-native': path.resolve(projectRoot, 'node_modules/react-native'),
26+
};
27+
28+
const escapeForRegExp = (p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
29+
config.resolver.blockList = [
30+
new RegExp(`^${escapeForRegExp(path.resolve(monorepoRoot, 'node_modules/react-native'))}/.*`),
31+
new RegExp(`^${escapeForRegExp(path.resolve(monorepoRoot, 'node_modules/react'))}/.*`),
32+
];
33+
1834
module.exports = config;

0 commit comments

Comments
 (0)