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

报错:重复注册RNCWebView,react-native-webview版本冲突求助

解决React Native中RNCWebView重复注册的问题

问题根源

你的项目中两个第三方依赖分别引入了不同版本的react-native-webview:

  • react-native-linkedin@2.1.1依赖react-native-webview@7.0.5
  • react-native-simple-twitter@3.0.6依赖react-native-webview@8.2.1
    两个版本同时存在导致组件重复注册,触发报错:

ERROR Invariant Violation: Tried to register two views with the same name RNCWebView, js engine: hermes

解决方案

方法一:用resolutions强制统一版本(推荐)

npm项目操作步骤

  1. 在项目根目录的package.json中添加resolutions字段,指定统一版本(建议选较高的8.2.1):
"resolutions": {
  "react-native-webview": "8.2.1"
}
  1. 重新安装依赖:
npm install
  1. 清理缓存并重构项目:
npm start -- --reset-cache
# iOS项目额外执行
cd ios && pod install && cd ..
# 重新运行项目
npx react-native run-android
npx react-native run-ios

yarn项目操作步骤

  1. 在package.json中添加同样的resolutions字段;
  2. 执行:
yarn install
  1. 后续清理缓存和重构步骤同npm项目。

方法二:手动合并依赖

如果resolutions无效,尝试以下步骤:

  1. 卸载所有版本的react-native-webview:
npm uninstall react-native-webview
  1. 安装指定版本到根依赖:
npm install react-native-webview@8.2.1
  1. 自动合并重复依赖:
npm dedupe
  1. 执行npm ls react-native-webview确认版本统一,再清理缓存重新构建。

验证

执行npm ls react-native-webview,输出应只显示一个统一版本的react-native-webview,无分支子依赖版本。

内容的提问来源于stack exchange,提问作者Aïcha Touré

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:57:10