React Native 不变违背:尝试注册两个名称相同的视图RNCSafeAreaProvider,js engine:爱马仕

wtzytmuj  于 2023-03-19  发布在  React
关注(0)|答案(3)|浏览(85)

我在尝试从“react-native-gifted-chat”导入和使用GiftedChat组件时遇到此错误:
Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider, js engine: hermes
我已经尝试了这里列出的几件事。人们似乎对其他与“react-native-safe-area-context”相关的包也有类似的问题。

  • 我已经更新了“react-native-safe-area-context”(在本文发表时为4.2.5)
  • 已卸载“React Native安全区域上下文”
  • RM节点模块
  • rm -rf ios/Pod和ios/Pod文件.lock
  • rm包-锁. json
  • npm安装
  • 重新安装pod-〉npx pod安装
  • 再次生成项目到相同的错误

我没有使用expo,但我使用的是React Native CLI。
在我看来,这个问题是与“React原生天赋聊天”。
详情:

  • “天然React”:“0.66.4英寸”
  • “React-本地-安全-区域-上下文”:“^3.1.9”
  • “React-原生-礼物-聊天”:“^1.0.0”

如果任何人有任何想法或见解,我将不胜感激。如果我找到一个解决方案,我会把它作为一个评论。

d8tt03nd

d8tt03nd1#

根据this发布,错误意味着同一扩展被安装了多次。
检查使用“React-本地-安全-区域-视图”的位置
npm list react-native-safe-area-context
结果:

├─┬ @react-navigation/bottom-tabs@6.3.1
│ ├─┬ @react-navigation/elements@1.3.3
│ │ └── react-native-safe-area-context@3.1.9 deduped
│ └── react-native-safe-area-context@3.1.9 deduped
├─┬ @react-navigation/stack@6.2.1
│ └── react-native-safe-area-context@3.1.9 deduped
├─┬ react-native-gifted-chat@1.0.0
│ └── react-native-safe-area-context@4.2.4
└── react-native-safe-area-context@3.1.9

看起来gifted chat正在引入4.2.4和3.1.9
将“React-本地-安全-区域-上下文”更新为最新版本(4.2.5)
运行npm dedupe
“react-native-gifted-chat”似乎仍有两个版本

├─┬ @react-navigation/bottom-tabs@6.3.1
│ ├─┬ @react-navigation/elements@1.3.3
│ │ └── react-native-safe-area-context@4.2.5 deduped
│ └── react-native-safe-area-context@4.2.5 deduped
├─┬ @react-navigation/stack@6.2.1
│ └── react-native-safe-area-context@4.2.5 deduped
├─┬ react-native-gifted-chat@1.0.0
│ └── react-native-safe-area-context@4.2.4
└── react-native-safe-area-context@4.2.5

这看起来很奇怪,所以我检查了node_modules node_modules/node_modules/react-native-gifted-chat/package.json中的包本身,发现依赖项特别要求4.2.4

"dependencies": {
    "@expo/react-native-action-sheet": "3.13.0",
    "dayjs": "1.8.26",
    "prop-types": "15.7.2",
    "react-native-communications": "2.2.1",
    "react-native-iphone-x-helper": "1.3.1",
    "react-native-lightbox-v2": "0.9.0",
    "react-native-parsed-text": "0.0.22",
    --> "react-native-safe-area-context": "4.2.4", <--
    "react-native-typing-animation": "0.1.7",
    "use-memo-one": "1.1.1",
    "uuid": "3.4.0"
  },

他们不需要^4.2.4,而是专门要求版本4.2.4
注:**^**字符定义了一个可接受的版本范围,包括从指定版本到下一版本的所有补丁和次要版本,但不包括下一版本。2因此“^1.2.3”可以近似地扩展为“〉=1.2.3〈2.0.0”。
什么意思?
我安装了“react-native-gifted-chat”所需的版本,它将与所有其他依赖项一起工作,然后检查它是否最终删除了重复数据。
npm install react-native-safe-area-context@4.2.4
npm list react-native-safe-area-context
最终重复数据消除

├─┬ @react-navigation/bottom-tabs@6.3.1
│ ├─┬ @react-navigation/elements@1.3.3
│ │ └── react-native-safe-area-context@4.2.4 deduped
│ └── react-native-safe-area-context@4.2.4 deduped
├─┬ @react-navigation/stack@6.2.1
│ └── react-native-safe-area-context@4.2.4 deduped
├─┬ react-native-gifted-chat@1.0.0
│ └── react-native-safe-area-context@4.2.4 deduped
└── react-native-safe-area-context@4.2.4

错误已修复。
别忘了重新安装pod。

TL;DR

  • “react-native-gifted-chat”没有正确编写他们的package.json。
  • 它们特别需要版本4.2.4的“react-native-safe-area-context”
  • 它们应该需要版本^4.2.4(〉=4.2.4〈5.0.0)
  • 安装此特定版本可修复此问题,因为没有使用两个版本的软件包。npm install react-native-safe-area-context@4.2.4
  • 也可以为“react-native-gifted-chat”打补丁,修复刚才列出的问题
  • 别忘了重新安装你的pod和所有的爵士乐
tzxcd3kk

tzxcd3kk2#

对我来说,在将react-native-safe-area-context升级到4.3.3版本后,它工作得很好

npm i react-native-safe-area-context@4.3.3
wf82jlnq

wf82jlnq3#

我有同样的问题(当处理与React原生天赋聊天时),以下是我所做的:1- npm副产物
2-npm lsReact Native安全区上下文
如果你有一个以上的版本运行下面的npm i react-native-safe-area-context@
3-删除节点模块4-运行npm i

相关问题