简体   繁体   English

Invariant Violation:试图注册两个同名的视图RNCSafeAreaProvider,js引擎:hermes

[英]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 have updated "react-native-safe-area-context" (4.2.5 at the time of this post)我已经更新了“react-native-safe-area-context”(发表这篇文章时为 4.2.5)
  • uninstalled "react-native-safe-area-context"卸载“反应原生安全区域上下文”
    • rm node_modules rm node_modules
    • rm -rf ios/Pods && ios/Podfile.lock rm -rf ios/Pods && ios/Podfile.lock
    • rm package-lock.json rm package-lock.json
    • npm install npm安装
    • reinstall pods -> npx pod-install重新安装 pod -> npx pod-install
    • build the project again to the same error再次构建项目到相同的错误

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:细节:

  • "react-native": "0.66.4" “反应原生”:“0.66.4”
  • "react-native-safe-area-context": "^3.1.9" “反应原生安全区域上下文”:“^3.1.9”
  • "react-native-gifted-chat": "^1.0.0" “react-native-gifted-chat”:“^1.0.0”

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;博士

  • "react-native-gifted-chat" did not write their package.json correctly. “react-native-gifted-chat”没有正确写出他们的 package.json。
  • They specifically require version 4.2.4 of "react-native-safe-area-context"他们特别需要 4.2.4 版的“react-native-safe-area-context”
  • They should require versions ^4.2.4 (>=4.2.4 < 5.0.0)他们应该需要版本 ^4.2.4 (>=4.2.4 < 5.0.0)
  • Installing this specific version fixes the issue since there is not two version of the package being used.安装此特定版本可解决问题,因为没有使用两个版本的 package。 npm install react-native-safe-area-context@4.2.4
  • Could alternatively do a patch for "react-native-gifted-chat" making the fix just listed或者可以为“react-native-gifted-chat”做一个补丁,使刚刚列出的修复
  • Don't forget to reinstall your pods and all that jazz不要忘记重新安装你的豆荚和所有爵士乐

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.

相关问题 不变违规:尝试使用@react-navigation/stack 注册两个具有相同名称 RNCSafeAreaProvider 错误的视图 - Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider error with @react-navigation/stack 试图注册两个具有相同名称的视图 RNCSafeAreaProvider - Tried to register two views with the same name RNCSafeAreaProvider 获取错误不变违规:试图注册两个具有相同名称的视图 - Getting error Invariant Violation: Tried to register two views with the same name Invariant Violation:试图注册两个同名的视图 RNDateTimePicker - Invariant Violation: Tried to register two views with the same name RNDateTimePicker 不变违规:尝试注册两个具有相同名称的视图 RNCAndroidDropdownPicker - Invariant Violation: Tried to register two views with the same name RNCAndroidDropdownPicker Invariant Violation:试图注册两个同名的视图RNCWebview - Invariant Violation: Tried to register two views with the same name RNCWebview Invariant Violation:试图注册两个具有相同名称的视图 RNCWebView - Invariant Violation:Tried to register two views with the same name RNCWebView IOS 上的“试图注册两个具有相同名称的 RNCSafeAreaProvider 视图”错误 - “tried to register two views with the same name RNCSafeAreaProvider” error on IOS 原生 UI 组件抛出 Invariant Violation:试图注册两个同名的视图 FridgeCameraView - Native UI Component throws Invariant Violation: tried to register two views with the same name FridgeCameraView 不变违规:试图在 React Native 中注册两个具有相同名称 RNCAndroidDialogPicker 的视图 - Invariant Violation: Tried to register two views with the same name RNCAndroidDialogPicker in react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM