Expo项目导入Reanimated 2的Animated组件时持续报错求助
解决Expo项目中react-native-reanimated导入报错问题
针对你遇到的Error: Exception in HostFunction: java.lang.IllegalArgumentException: Could not find @ReactModule annotation in com.swmansion.gesturehandler.react.RNGestureHandlerModule错误,按以下步骤解决:
匹配依赖版本
确保react-native-gesture-handler和react-native-reanimated的版本与你当前使用的Expo SDK版本兼容。比如Expo SDK 49对应react-native-gesture-handler@~2.12.0、react-native-reanimated@~3.3.0,根据你的SDK版本调整package.json中的依赖版本后重新安装。重新安装依赖
删除旧依赖文件后重新安装:# npm用户 rm -rf node_modules package-lock.json npm install # yarn用户 rm -rf node_modules yarn.lock yarn install正确配置Gesture Handler入口
在项目的根入口文件(App.tsx/App.js)最顶部添加导入,且必须放在所有其他导入之前:import 'react-native-gesture-handler';清除Expo缓存
启动项目时清除缓存,避免旧构建文件干扰:npx expo start --clear排查冲突依赖
检查package.json中是否存在其他与react-native-gesture-handler相关的冲突依赖,如有则删除后重新安装。
内容的提问来源于stack exchange,提问作者Jeoffrey Duke
相关产品推荐
相关产品推荐

