[英]Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider, js engine: hermes
I am getting this error when trying to import and use the GiftedChat component from "react-native-gifted-chat":尝试从“react-native-gifted-chat”导入和使用 GiftedChat 组件时出现此错误:
Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider, js engine: hermes
I have tried several things listed here .我已经尝试了这里列出的几件事。 People appear to have similar issues with other packages relating to "react-native-safe-area-context".人们似乎对与“react-native-safe-area-context”相关的其他软件包有类似的问题。
I am NOT using expo but I am using the React Native CLI.我没有使用 expo 但我使用的是 React Native CLI。
It appears to me that the issue is with "react-native-gifted-chat".在我看来,问题在于“react-native-gifted-chat”。
Details:细节:
If anyone has any ideas or insight I would appreciate it.如果有人有任何想法或见解,我将不胜感激。 If I find a solution I will post it as a comment.如果我找到解决方案,我会将其作为评论发布。
According to this post the error means the same extension is installed multiple times.根据这篇文章,错误意味着多次安装相同的扩展。
checked where "react-native-safe-area-view" was being used检查使用“react-native-safe-area-view”的位置
npm list react-native-safe-area-context
Results:结果:
├─┬ @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
it appears that gifted chat is pulling in 4.2.4 and 3.1.9似乎天才聊天正在拉入 4.2.4 和 3.1.9
updated "react-native-safe-area-context" to latest version (4.2.5)将“react-native-safe-area-context”更新到最新版本(4.2.5)
ran npm dedupe
运行npm dedupe
"react-native-gifted-chat" appeared to still be pulling in two versions “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
This seemed odd so I check the package itself in node_modules node_modules/node_modules/react-native-gifted-chat/package.json
and found that the dependencies requested 4.2.4 specifically这看起来很奇怪,所以我在 node_modules node_modules/node_modules/react-native-gifted-chat/package.json
中检查了 package 本身,发现依赖项专门要求 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"
},
instead of requiring ^4.2.4 they specifically require version 4.2.4而不是需要 ^4.2.4 他们特别需要版本 4.2.4
side note: ^ character defines a range of acceptable versions that include all patch and minor versions from the ones specified up to, but not including, the next version.旁注: ^字符定义了一系列可接受的版本,包括从指定版本到下一个版本的所有补丁和次要版本,但不包括下一个版本。 So "^1.2.3" can be approximately expanded as ">=1.2.3 <2.0.0".所以“^1.2.3”可以近似扩展为“>=1.2.3 <2.0.0”。
What does mean?这是什么意思?
I installed the required version for "react-native-gifted-chat" which will work with all other dependencies then checked if it was finally deduped.我为“react-native-gifted-chat”安装了所需的版本,它将与所有其他依赖项一起工作,然后检查它是否最终被删除。
npm install react-native-safe-area-context@4.2.4
npm list react-native-safe-area-context
finally deduped终于去重了
├─┬ @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
Error fixed.错误已修复。
Don't forget to reinstall your pods.不要忘记重新安装您的 pod。
TL;DR TL;博士
npm install react-native-safe-area-context@4.2.4
For me its working fine after upgrading react-native-safe-area-context to version 4.3.3对我来说,将 react-native-safe-area-context 升级到版本 4.3.3 后它工作正常
npm i react-native-safe-area-context@4.3.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.