OGeek|极客世界-中国程序员成长平台

标题: ios - 如何防止 react-native-device-info 在我的设置中导致 React 歧义? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:58
标题: ios - 如何防止 react-native-device-info 在我的设置中导致 React 歧义?

我在将 react-native-device-info 安装到现有的 react-native 项目(使用 create-react-native-app 创建)时遇到问题然后弹出)

我跑:

yarn 添加 react native 设备信息 yarn 安装 react-native 链接 react-native-device-info cd ios && pod 安装 & cd ..

pod install 安装RNDeviceInfo,还安装React作为依赖?

然后我照常运行 yarn ios

MetroBundler 失败:

``` 此警告是由两个不同文件中具有相同名称的 @providesModule 声明引起的。 加载依赖图,完成。 错误:捆绑失败:不明确的解决方案:模块 /Users/thomasclarke/dev/mobile-notifications-native/index.js 尝试要求 react-native,但有几个提供此模块的文件。您可以删除或修复它们:

我提出了错误报告,因为这显然是 Not Acceptable 行为,但我可以通过我的设置解决这个问题吗?



Best Answer-推荐答案


事实证明,您可以链接到 node_modules 中的 react-native,它提供了必要的依赖项。在现有项目中默认没有这样做,所以这里是过程:

1) 从“干净”开始(例如,没有 react-native-device-info 行为)。在此之前搞砸了,我还发现我必须清除我的 node_modules 和我的 ios/Pods 目录来清除遗留的 React 包。

2) 更新您的 Podfile 以链接到 React(您还必须添加任何 relevant subspecs 和一个单独的 Yoga pod)

以下是要添加到 podfile 的行: pod 'React', :path => '../node_modules/react-native', :subspecs => [ '开发支持', '核', 'RCT动画', 'RCT图像', 'RCTLinkingIOS', 'RCT设置', 'RCTText' ] pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

3) 然后运行 ​​react-native link react-native-device-info

这会将 react-native-device-info 添加到您的 Podfile(以及 android 设置)

pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

4) 一切正常安装: yarn 安装 光盘 pods 安装

你现在应该有一个正常运行的构建!

关于ios - 如何防止 react-native-device-info 在我的设置中导致 React 歧义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52737251/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4