React Native 0.74.3中RNGestureHandlerModule缺失问题根因咨询
使用React Native 0.74.3搭配react-native-gesture-handler 2.17.1时,出现如下错误:
Invariant Violation: TurboModuleRegistry.getEnforcing(...):'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: true.TurboModule interop: true. Modules loaded:{"NativeModules":[],"TurboModules":["PlatformConstants","LogBox","SourceCode","AppState","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","DeviceInfo","ImageLoader","SoundManager","IntentAndroid","DeviceEventManager","NativeAnimatedModule","I18nManager"],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","HeadlessJsTaskSupport","LinkingManager","NativeReactNativeFeatureFlagsCxx","RNCSafeAreaContext","ReanimatedModule","RNGestureHandlerModule"]}
调试时发现NotFound列表中的所有模块均为null,需明确这类问题的根本原因。
- Bridgeless模式适配缺失:错误信息显示当前开启了
Bridgeless mode: true,React Native 0.74+默认启用该模式,但react-native-gesture-handler、reanimated等第三方模块尚未完全适配Bridgeless架构,导致它们的TurboModule无法被系统正确识别加载。 - 原生模块注册失败:
- 自动链接失效:RN的自动链接机制可能因版本不匹配、项目配置异常(如
android/settings.gradle或ios/Podfile未正确引入模块),使得模块的TurboModule注册代码未被打包进原生二进制文件。 - 手动注册方式错误:Bridgeless模式要求模块通过
TurboModuleManager完成注册,若仍沿用传统的NativeModules注册方式,就会出现模块找不到的情况。
- 自动链接失效:RN的自动链接机制可能因版本不匹配、项目配置异常(如
- 版本兼容性冲突:react-native-gesture-handler 2.17.1与RN 0.74.3的Bridgeless模式存在兼容性bug,该版本组合下模块的TurboModule实现未适配RN最新的Bridgeless架构规范。
- 构建缓存干扰:旧构建缓存(如Android的
build目录、iOS的DerivedData)可能残留了未更新的模块注册信息,导致新模块的注册代码未被正确编译到原生包中。
内容的提问来源于stack exchange,提问作者androider

