You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native报错:GestureHandlerRootView同名视图重复注册

报错根因

Tried to register two views with the same name GestureHandlerRootView 是React Native原生层的重复注册校验报错,触发原因是项目依赖中同时存在两份及以上不同版本的react-native-gesture-handler包。
你当前安装的@rainbow-me/animated-charts@^1.0.0-alpha.6自身内部依赖了react-native-gesture-handler,和你手动在dependencies中声明的react-native-gesture-handler@~2.2.1版本未对齐,打包时两个版本的包都被引入,尝试注册同名的GestureHandlerRootView原生视图就会抛出这个错误。

你当前的package.json依赖配置如下:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4",
    "@rainbow-me/animated-charts": "^1.0.0-alpha.6",
    "expo": "~45.0.0",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-gesture-handler": "~2.2.1",
    "react-native-reanimated": "~2.8.0",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}
修复步骤
  • 在项目根目录的package.json顶层添加resolutions字段,强制整个项目所有依赖都使用你指定版本的react-native-gesture-handler,从根源消除多版本共存问题:
"resolutions": {
  "react-native-gesture-handler": "~2.2.1"
}
  • 清理缓存并重新安装依赖,在项目根目录依次执行以下命令:
# 删除旧依赖和锁文件
rm -rf node_modules yarn.lock
# 重新拉取依赖
yarn install
# 清除Expo构建缓存并启动项目
expo start -c
  • 校验修复结果:执行yarn list react-native-gesture-handler,确认输出列表中仅存在2.2.x版本的包,无其他嵌套在第三方依赖目录下的重复版本即可。

额外注意:确保项目入口文件(通常是App.js/index.js)的最顶部第一行就写入import 'react-native-gesture-handler',这是该库的强制要求,漏写会引发其他手势相关异常。

内容的提问来源于stack exchange,提问作者supermariotrener

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 14:45:29