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

报错Invariant Violation:重复注册RNCWebView视图,求解决办法

解决"Invariant Violation: Tried to register two views with the same name RNCWebView"错误
  • 检查重复依赖

    • 项目可能同时安装了react-native-webview和其他内置旧版webview的依赖(比如部分UI库)。执行npm list react-native-webview或yarn list react-native-webview查看依赖树,找出重复引入的包。
    • 若发现重复,在package.json中添加resolutions字段(npm需先安装npm-force-resolutions,yarn直接支持),强制统一webview版本:
      "resolutions": {
        "react-native-webview": "13.6.3" // 替换成你项目兼容的版本
      }
      
      之后重新安装依赖:npm install或yarn install
  • 清理原生端缓存

    • iOS:
      • 删除ios/Pods文件夹和Podfile.lock
      • 执行pod install --repo-update
      • 通过Xcode清理编译缓存:菜单栏 -> Product -> Clean Build Folder
    • Android:
      • 删除android/.gradle、android/app/build文件夹
      • 执行./gradlew clean(Windows系统用gradlew clean)
  • 排查自动链接冲突

    • 手动检查ios/Podfile,如果重复引入了RNCWebView的pod,删除多余条目后重新执行pod install
    • 检查android/settings.gradle和android/app/build.gradle,若有重复添加的webview依赖配置,删除后重新编译
  • 重装webview依赖

    • 先卸载:npm uninstall react-native-webview或yarn remove react-native-webview
    • 清理缓存:npm cache clean --force或yarn cache clean
    • 重新安装对应兼容版本:npm install react-native-webview@xxx或yarn add react-native-webview@xxx(xxx替换为具体版本号)
    • RN 0.60+自动完成链接,旧版本需额外执行react-native link react-native-webview
  • 清除metro缓存启动

    • 启动项目时添加参数清除metro缓存:react-native start --reset-cache

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 20:20:36