react-native ios Podfile 问题与“use_native_modules!”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/56917963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
react-native ios Podfile issue with "use_native_modules!"
提问by Cory Robinson
In my react-native project ([email protected]) in the ios/ dir I run pod install
and get this error:
在我的 ios/ 目录中的 react-native 项目 ([email protected]) 中,我运行pod install
并收到此错误:
[!] Invalid `Podfile` file: no implicit conversion of nil into String.
# from /Users/coryrobinson/projects/hhs2/ios/Podfile:37
# -------------------------------------------
#
> use_native_modules!
# end
# -------------------------------------------
I haven't added or changed anything in this Podfile - it's all react-native generated. (I'm not experienced in iOS dev so this might be a simple fix, I just don't know what to look for :-|) Thanks for any help!
我没有在这个 Podfile 中添加或改变任何东西——它都是 react-native 生成的。(我没有 iOS 开发经验,所以这可能是一个简单的修复,我只是不知道要寻找什么:-|) 感谢您的帮助!
Here is my Podfile
这是我的 Podfile
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'hhs2' do
# Pods for hhs2
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
pod 'RNFS', :path => '../node_modules/react-native-fs'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
target 'hhs2Tests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
end
target 'hhs2-tvOS' do
# Pods for hhs2-tvOS
target 'hhs2-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
回答by Meabed
Here is the correct answer:
以下是正确答案:
1 - Your POD File should contain this line on top
1 - 您的 POD 文件应在顶部包含此行
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
2 - Make sure your package.json
and node_module
folders has this module installed
2 - 确保您的package.json
和node_module
文件夹已安装此模块
cli-platform-ios/native_modules
cli-platform-ios/native_modules
3 - If you didn't find after you run yarn install
- means you have old cache node_modules in your machine and you need to clean it before reinstalling the package again.
3 - 如果你在运行后没有找到yarn install
- 意味着你的机器中有旧的缓存 node_modules,你需要在重新安装包之前清理它。
4 - Clean cache yarn cache clean
4 - 清理缓存 yarn cache clean
5 - Make sure you have this file react-native.config.js
and its configuration is VALID - and it doesn't have non-existing NPM packages - this step is LAST AND MOSTLY THE CAUSE of the error
5 - 确保你有这个文件react-native.config.js
并且它的配置是有效的 - 并且它没有不存在的 NPM 包 - 这一步是最后,也是导致错误的主要原因
Example of my react-native.config.js
我的例子 react-native.config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
dependencies: {}, // make sure this dependencies are all valid installed packages or empty if you don't need it
};
6 - Install node packages yarn install
and your pods should work now! pod install --repo-update
6 - 安装节点包yarn install
,你的 pod 现在应该可以工作了!pod install --repo-update
HAPPY coding!
快乐编码!
回答by MoOx
If you are using
如果您正在使用
pod install --project-directory=ios
you might need to tweak the Podfile by replacing
您可能需要通过替换来调整 Podfile
use_native_modules!
use_native_modules!
to
到
use_native_modules!(".")
use_native_modules!(".")
Maybe this behavior will be improved in the future, I opened an issue about it https://github.com/react-native-community/cli/issues/657
也许这种行为将来会得到改善,我打开了一个关于它的问题https://github.com/react-native-community/cli/issues/657
回答by Vitor Lopes
Downgraded @react-native-community/cli-platform-ios from 3.1.0 to 3.0.0 and it worked.
将@react-native-community/cli-platform-ios 从 3.1.0 降级到 3.0.0 并且它起作用了。
Added
添加
"@react-native-community/cli-platform-ios": "3.0.0"
to package.json.
到 package.json。
Run npm install and then pod install to get it working again.
运行 npm install 然后 pod install 让它再次工作。
回答by ToniG
i just dropped the whole node_modules and RN cache folder and did a clean reinstall, this fixed the "use_native_modules" problem so far....but after that i had to hassle a lot with other libs which where just not RN0.60 ready ;)
我刚刚删除了整个 node_modules 和 RN 缓存文件夹并重新安装,这解决了到目前为止的“use_native_modules”问题...... )
回答by Naveen Raju
For me, I deleted the node_modules
and installed again by using npm install
. After that, I navigated to /ios
folder and ran pod install
it worked.
对我来说,我删除了node_modules
并使用npm install
. 之后,我导航到/ios
文件夹并运行pod install
它。
回答by jsina
this is because the outdate yarn version on your device, if you on macOS you can upgrade/install the yarn with follow this link: here it is
这是因为您设备上的纱线版本过时,如果您在 macOS 上,您可以按照以下链接升级/安装纱线: 这里是
be awareto delete node-module
and yarn.lock
file, install all packages again, navigate to iosfolder and run pod install
.
请注意删除node-module
和yarn.lock
归档,再次安装所有软件包,导航到ios文件夹并运行pod install
.
回答by B. Mohammad
Verify if you have @react-native-community/cli-platform-ios
in your package.json,
设备是否已经 @react-native-community/cli-platform-ios
在你的package.json,
if you dont run:
如果你不运行:
npm install @react-native-community/cli-platform-ios
npm install @react-native-community/cli-platform-ios
then
然后
cd ios && pod install
cd ios && pod install
回答by cheesus
I got this error after I tried to react-native run-ios
an Expo app. The error I got indicated that something was wrong with the Pods, so I ran cd ios && pod install
, which is how I got a similar error as the OP.
尝试react-native run-ios
使用 Expo 应用程序后出现此错误。我得到的错误表明 Pod 有问题,所以我跑了cd ios && pod install
,这就是我遇到与 OP 类似的错误的原因。
In that case, you obviously need to expo start
instead of react-native run-ios
.
在这种情况下,您显然需要expo start
代替react-native run-ios
.
回答by Matthew Gruman
This started happening out of the blue today, and the problem was a space in my directory structure. Ex:
今天突然开始发生这种情况,问题是我的目录结构中有一个空格。前任:
/path/to/Directory\ Name/RNProject throws the !native_modules error /path/to/DirectoryName/RNProject works as it should
/path/to/Directory\ Name/RNProject 抛出 !native_modules 错误 /path/to/DirectoryName/RNProject 正常工作
Pods was looking for "Directory. "
Pods 正在寻找“目录”。
回答by Tyler Agnew
Does anyone have a consistently recreatable solution for this issue that does not revolve around getting rid of use_native_modules? I have looked into:
有没有人对这个问题有一个始终如一的可重新创建的解决方案,而不是围绕摆脱 use_native_modules?我调查过:
- Changing Ruby Version
- Changing CocoaPods version
- Invalidating NPM and Cocoapods cache
- 更改 Ruby 版本
- 更改 CocoaPods 版本
- 使 NPM 和 Cocoapods 缓存失效
And I am unable to fix the issue. It appears to be some npm dependency, but others on my team are not seeing it.
我无法解决这个问题。它似乎是一些 npm 依赖项,但我团队中的其他人没有看到它。