繁体   English   中英

错误:不变违规:requireNativeComponent:在 UIManager 中找不到“RNCPicker”

[英]Error: Invariant Violation: requireNativeComponent: "RNCPicker" was not found in the UIManager

概述:

我使用 TypeScript 构建了一个 NPM 库,距离我上次更新它已经快 9 个月了(我没有时间)。 但是,它使用以下库:

  1. 反应本机模式
  2. @react-native-picker/picker (以前是@react-native-community/picker ,但现在不推荐使用该库以支持新库
  3. @react-native-community/datetimepicker

我的图书馆(react-native-ultimate-modal-picker) package.json

我将上面列出的所有 3 个库都设置为peerDependencies ,但我不确定我是否缺少像podfiles这样的其他东西。

"peerDependencies": {
  "@react-native-community/datetimepicker": ">=3.0.0",
  "@react-native-picker/picker": ">=1.8.3",
  "react": "*",
  "react-native": "*",
  "react-native-modal": ">=11.0.0"
},

什么有效:

该代码在 iOS 模拟器中运行时有效,但是当将我的库react-native-ultimate-modal- picker 添加到项目时,它会给出错误。

错误:

Error: Invariant Violation: requireNativeComponent: "RNCPicker" was not found in the UIManager.

将 NPM 库导入项目:

import { DropdownList } from 'react-native-ultimate-modal-picker';

const testItems: Array<PickerValue> = [
  { label: '1', value: '1' },
];

<DropdownList
  title="Test"
  items={testItems}
  onChange={(value: string) => console.log(value)}
/>

Github 回购(我的图书馆目前不工作)

https://github.com/jefelewis/react-native-ultimate-modal-picker

问题的可能原因:

  • podfiles
  • 缓存?
  • NPM 库的不正确构建/导出?

可以尝试以下步骤:

  1. rm -rf node_modules && yarn cache clean && yarn install
  2. cd ios && pod install
  3. 从 ios 文件夹中的 yourapp.xcworkspace 文件中打开 xCode。
  4. Select 从 xCode 产品菜单中Clean Build Folder
  5. 直接从 xCode 产品菜单Run您的应用程序。

在你的 podfile 中添加这一行:

pod 'RNCPicker', :path => './ReactComponent/node_modules/@react-native-picker/picker'

您可能需要将路径更改为您的真实路径,就像您的 podfile 和 pod install 中的其他路径一样。

如果您使用 RN 高于 0.60的 react-native-picker-select ,您还需要安装@react-native-community/picker (不知道为什么它不是它的依赖项......)

npm install @react-native-community/picker

pod-install

以下解决方案对我有用。 安装下面提到的 package 除了 react-native-picker-select

// 反应原生 CLI

npm install @react-native-community/picker
npx pod-install

// Expo 用户

expo install @react-native-community/picker

信用 - https://blog.logrocket.com/how-to-use-react-native-picker-select/

为了工作,安装 npm 软件包和 pod install 或在 package.json 和 pod install 中添加这些行

"@react-native-picker/picker": "^2.4.4",

"react-native-picker-select": "^8.0.4",


像这样:

"dependencies": {
    "@react-native-picker/picker": "^2.4.4",
    "react": "18.1.0",
    "react-native": "0.70.1",
    "react-native-picker-select": "^8.0.4"
  },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM