stub rn codegen native component on web

This commit is contained in:
vineyardbovines
2026-07-23 12:41:40 -04:00
parent 10b027c35b
commit 96bd726c85
2 changed files with 27 additions and 0 deletions
@@ -0,0 +1,17 @@
/*
* Web stub for `react-native/Libraries/Utilities/codegenNativeComponent`.
*
* Deep `react-native/*` imports bypass the `react-native$ -> react-native-web`
* alias and drag RN core into the web bundle, where its platform-extension
* modules (e.g. Libraries/Utilities/Platform.js) resolve to themselves and
* throw a TDZ error at startup. Packages that import codegen specs
* unconditionally (react-native-uitextview) guard the native component behind
* a `Platform.OS === 'ios'` check, so nothing ever renders this on web.
*/
module.exports = function codegenNativeComponent(componentName) {
return function UnimplementedNativeComponent() {
throw new Error(
`Native component "${componentName}" was rendered on web. It has no web implementation.`,
)
}
}
+10
View File
@@ -62,6 +62,16 @@ module.exports = async function (env, argv) {
}
config = withAlias(config, {
'react-native$': 'react-native-web',
/*
* Codegen specs import this via a deep `react-native/*` path, which skips
* the exact-match alias above and pulls RN core into the web bundle. RN
* core's platform-extension modules have no `.web` variant, so they
* resolve to themselves and blow up with a TDZ error on startup.
*/
'react-native/Libraries/Utilities/codegenNativeComponent$': path.join(
__dirname,
'src/lib/web-shims/codegenNativeComponent.js',
),
'react-native-webview': 'react-native-web-webview',
'react-native-gesture-handler': false, // RNGH should not be used on web, so let's cause a build error if it sneaks in
'@sentry-internal/replay': false, // not used, ~300kb of dead weight