可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
In my react-native project (react-native@0.60) in the ios/ dir I run pod install
and get this error:
[!] 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!
Here is my 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
回答1:
Here is the correct answer:
1 - Your POD File should contain this line on top
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
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.
4 - Clean cache 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
Example of my react-native.config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/']
dependencies: {}, // make sure this deps 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
HAPPY coding!
回答2:
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 ;)
回答3:
If you are using
pod install --project-directory=ios
you might need to tweak the Podfile by replacing
use_native_modules!
to
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
回答4:
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.
回答5:
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
be aware to delete node-module
and yarn.lock
file, install all packages again, navigate to ios folder and run pod install
.
回答6:
Verify if you have @react-native-community/cli-platform-ios
in your package.json,
if you dont run:
npm install @react-native-community/cli-platform-ios
then
cd ios && pod install
回答7:
After removing several react-native npm packages (ie: react-native-bluetooth-serial, react-native-sound, and more...) pod install
works.
It appears the pod install error is related to older react-native packages that don't support cocoa pods? I'm not sure the details but removing those packages from node_modules & package.json solved my issue.
回答8:
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.
In that case, you obviously need to expo start
instead of react-native run-ios
.
回答9:
One of the reasons may be outdated version of Ruby. Use following command to upgrade it.
rvm install 2.6.1
rvm use 2.6.1 --default
Or you can follow below article, which has a detailed explanation of upgrading ruby and associated gems.
https://help.learn.co/en/articles/2789231-how-to-upgrade-from-ruby-2-3-to-2-6
回答10:
The issue is that:
use_native_modules!
is unsupported by earlier versions of CocoaPods. For example, our install was the app downloaded from the CocaoPods website. That version is 1.5.2
.
Run:
pod --version
to check which version. If need be, uninstall and then re-install but in Terminal by running:
sudo gem install cocoapods
At least as of late October 2019, the current gem version available is 1.8.4
. Once successfully installed, re-attempt the pod install
and hopefully all is well.
回答11:
Go to this repository :
ProjectName -> ios -> Podfile
In Podfile, delete use_native_modules!
Execute again pod install
And Enjoy your use
回答12:
Getting rid of the line use_native_modules!
works as well. Maybe this has been deprecated or syntax has changed? Curious to hear from others.
Update: Seems to be an issue with react-native 0.60.0. Until a release fixes this bug, 0.59.10 can be explicitly installed, and you only need to add CocoaPods as necessary.
react-native init APP_NAME --version react-native@0.59.10