From be6cd8ad9a89a83f2f44f8b0bc2f94dab3e49a8d Mon Sep 17 00:00:00 2001 From: Pablo Giraud-Carrier Date: Fri, 5 Jun 2026 18:41:01 +0200 Subject: [PATCH] fix(example): resolve react/react-native from the example app 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. --- example/metro.config.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/example/metro.config.js b/example/metro.config.js index d588dad..6e70bda 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -15,4 +15,20 @@ config.resolver.nodeModulesPaths = [ path.resolve(monorepoRoot, 'node_modules'), ]; +// The monorepo root also carries its own (newer) react / react-native, pulled in +// by npm auto-installing the library's peerDependencies. Pin the singletons to the +// example's copies so Metro and React Native codegen never mix versions — mixing +// breaks native component codegen (e.g. "Unable to determine event arguments" in +// VirtualViewNativeComponent). +config.resolver.extraNodeModules = { + react: path.resolve(projectRoot, 'node_modules/react'), + 'react-native': path.resolve(projectRoot, 'node_modules/react-native'), +}; + +const escapeForRegExp = (p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +config.resolver.blockList = [ + new RegExp(`^${escapeForRegExp(path.resolve(monorepoRoot, 'node_modules/react-native'))}/.*`), + new RegExp(`^${escapeForRegExp(path.resolve(monorepoRoot, 'node_modules/react'))}/.*`), +]; + module.exports = config;