React Native 错误:不变量冲突:requireNativeComponent:在UIManager中找不到“RNCPicker”

szqfcxe2  于 2023-06-30  发布在  React
关注(0)|答案(6)|浏览(245)

概述:

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

  1. react-native-modal
    1.@react-native-picker/picker(以前是@react-native-community/picker,但该库现在已弃用,转而支持新库
    1.@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库的构建/导出不正确?
5ssjco0h

5ssjco0h1#

可以尝试以下步骤:

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

8wigbo562#

在你的podfile中添加这一行:

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

路径你可能需要改变到你的真实的路径像其他人在你的podfile和pod安装一次。

r7knjye2

r7knjye23#

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

npm install @react-native-community/picker

pod-install
polhcujo

polhcujo4#

下面的解决方案对我很有效。除了react-native-picker-select之外,安装下面提到的包
// React Native 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/

fzwojiic

fzwojiic5#

要工作,请同时安装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"
  },
tf7tbtn2

tf7tbtn26#

手动安装pod似乎起作用了。在podfile中添加pod 'RNCPicker',:path => '../node_modules/@react-native-picker/picker'
注意:路径可能会有所不同,具体取决于项目的结构。如果podfile位于ios文件夹中(使用react-native生成的项目

相关问题