【问题标题】:Error: Invariant Violation: requireNativeComponent: "RNCPicker" was not found in the UIManager错误:不变违规:requireNativeComponent:在 UIManager 中找不到“RNCPicker”
【发布时间】:2021-05-15 19:57:35
【问题描述】:

概述:

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

  1. react-native-modal
  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 Repo(我的图书馆目前无法使用)

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

问题的可能原因:

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

【问题讨论】:

    标签: reactjs react-native npm libraries


    【解决方案1】:

    可以尝试以下步骤:

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

    【讨论】:

    • 谢谢你,它工作得很好!我有同样的问题
    【解决方案2】:

    在你的 podfile 中添加这一行:

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

    您可能需要将路径更改为您的真实路径,就像您的 podfile 中的其他路径一样,然后再次安装 pod。

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 2019-08-27
      • 2020-09-02
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多