在将react-native-device-info安装到现有的react本机项目(使用create-react-native-app创建,然后弹出)时,我遇到了问题。
我跑:
yarn add react-native-device-info yarn install react-native link react-native-device-info cd ios && pod install & cd ..
pod安装RNDeviceInfo,但React也是一个依赖项吗?
然后,我像往常一样运行yarn ios。
MetroBundler在以下方面失败:
`此警告是由跨两个不同文件的名称相同的@providesModule声明引起的。加载依赖关系图,完成。错误:捆绑失败:模组/Users/thomasclarke/dev/mobile-notifications-native/index.js试图要求react-native,但是有几个文件提供了这个模块。您可以删除或修复它们:
/Users/thomasclarke/dev/mobile-notifications-native/ios/Pods/React/package.json/Users/thomasclarke/dev/mobile-notifications-native/node_modules/react-native/package.json `我提出了一个错误报告,因为这显然是不可接受的行为,但这是什么东西,我可以围绕我的设置?
发布于 2018-10-12 09:11:23
事实证明,您可以链接到node_modules中的react本机,这提供了必要的依赖。在现有项目中,默认情况下没有这样做,因此下面是一个过程:
1)从“干净”开始(例如,没有react-native-device-info行为)。在此之前,我还发现我必须同时清除我的node_modules和ios/Pods目录,以清除遗留的React包。
2)更新您的Podfile链接以作出反应(您还必须添加任何relevant subspecs和单独的瑜伽吊舱)
下面是要添加到podfile中的行:pod 'React', :path => '../node_modules/react-native', :subspecs => [ 'DevSupport', 'Core', 'RCTAnimation', 'RCTImage', 'RCTLinkingIOS', 'RCTSettings', 'RCTText' ] pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
3)运行react-native link react-native-device-info
这将向您的Podfile添加react本机设备-信息(连同android安装程序)。
pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
4)按常规安装所有设备:yarn install cd ios pod install
现在你应该有一个有效的构建了!
https://stackoverflow.com/questions/52737251
复制相似问题