55

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
Cory Robinson
  • 4,616
  • 4
  • 36
  • 53

26 Answers26

58

Here is the correct answer:

1 - Your Podfile 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 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

HAPPY coding!

mokagio
  • 16,391
  • 3
  • 51
  • 58
Meabed
  • 3,828
  • 1
  • 27
  • 37
  • 2
    Should react-native.config.js file be in root folder or in ios? – twboc Jan 02 '20 at 11:56
  • Also make sure your config file uses `require` rather than `import`. ESLint auto-fixes broke mine by swapping those out. – Stephen Saucier Feb 05 '20 at 16:28
  • 1
    Also if you don't have `use_native_modules!` in your pod file it won't work, so add it in there. – SudoPlz Apr 03 '20 at 19:56
  • I started with the error written above, followed @Meabed suggestions, and now I am getting '[!] Invalid `Podfile` file: A JSON text must at least contain two octets!.' for the 'use_native_modules!' line. Any idea why? I tried looking for this error in SO and cannot make any of the suggsted solutions to work. – Yossi Apr 25 '20 at 09:39
  • @Yossi please share your pod file in gist. – Meabed Apr 25 '20 at 14:26
  • @Meabed I decided to try and recreate the project. If I face the same problem I will post it here. Thanks! – Yossi Apr 25 '20 at 18:11
  • 1
    FYI the module is called `@react-native-community/cli-platform-ios`, not `cli-platform-ios/native_modules`, in case anyone is trying to install it. – Shaun Saker Aug 15 '23 at 00:11
10

Downgraded @react-native-community/cli-platform-ios from 3.1.0 to 3.0.0 and it worked.

Added

"@react-native-community/cli-platform-ios": "3.0.0"

to package.json.

Run npm install and then pod install to get it working again.

Vitor Lopes
  • 101
  • 1
  • 3
5

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

MoOx
  • 8,423
  • 5
  • 40
  • 39
  • [!] Passing custom root to use_native_modules! is deprecated. - CLI detects root of the project automatically. The "" argument was ignored. – sina farbod Dec 07 '19 at 11:37
  • I had the opposite problem (if I understand you correctly) -- I get the the error if I (cd ios; pod install), but `pod install --project-directory=ios` works and I've used it for years. But I just tried a CI build on app center which assumes (cd ios; pod install) and it breaks. I've tried every fix in this question and nothing helps. (Except perhaps removing old RN packages that don't support cocoapods -- don't know how to identify those.) – chetstone Dec 12 '21 at 06:44
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.

jsina
  • 4,433
  • 1
  • 30
  • 28
4

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

B. Mohammad
  • 2,152
  • 1
  • 13
  • 28
3

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 ;)

ToniG
  • 41
  • 4
2

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.

Naveen Raju
  • 5,411
  • 1
  • 9
  • 9
  • Sharing some more details can be helpful, E.g where to find "node_modules" – Umair Afzal Aug 13 '20 at 05:16
  • @UmairAfzal - Google `node_modules`. It is a folder in your project; a local cache of all npm packages your project uses. (I think it is created when you do `npm install`.) Every project that uses `npm` will have this as a sub-folder of the project's root folder. – ToolmakerSteve Oct 21 '20 at 18:34
2

Ok, my guess is for most people, the accepted answer will fix their issue. For me, the fix was so bizarre, I had to add it here.

For whatever reason, I ended up creating an invalid AndroidManifest.xml file in my android native setup.

I looked at the full error output, and the first lines of the error referenced a line number and column number. At that point in my xml file I broke the xml formatting.

2 days of searching to find a GitHub Issue with a description of where to look.

Doug Watkins
  • 1,387
  • 12
  • 19
  • 1
    YEAH, same here... could not imagine how a broken AndroidManifest.xml could lead to IOS podlike issue – Rubycon Apr 26 '22 at 18:24
2

I too was having this very exact same issue and nothing here worked for me. In my particular case, I am using Nx monorepo tool and I had removed a package in my root level package.json, but forgot to correspondingly remove it from my Expo app package.json, so when I'd run run-ios target and it would try and build the pods, it'd fail for this reason (because symlinked package was missing). This might not be a solution for everyone, but if it'll save someone else 4 hours and a headache, why not post it

Isaac
  • 204
  • 2
  • 10
1

Don't use yarn install. Thats what worked for me...

  • Go to main folder
  • Delete nodes folder
  • Run sudo npm install or just npm install
  • cd ios
  • pod install
1

Having same issue while building app on AppCenter, locally works perfectly

Is there any possibility to track this error? Cause I've seen that there can be a lof of reasons why I see it.

Kamil P
  • 782
  • 1
  • 12
  • 29
1

Easily:

  1. Run sudo xcode-select --switch /Applications/Xcode.app in the root of your React Native project.
  2. In the ios folder run pod install.

Edit:

No hacks with any of:

  • @react-native-community/cli-platform-ios
  • require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
  • require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

were needed.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
1

Steps to follow :

  1. npm install
  2. npm install -g react-native-cli
  3. go to your ios folder -> cd ios
  4. pod install
Utkarsh
  • 11
  • 1
1

Same issue appeared after upgrading react native from 0.65 to 0.71. Running pod install got me this:

 #  from /Users/username/Documents/projectname/ios/Podfile:25
 #  -------------------------------------------
 #  target 'projectname' do
 >    config = use_native_modules!
 #  
 #  -------------------------------------------

Executing pod install --verbose command provided the following details:

/Users/username/Documents/projectname/node_modules/@react-native-community/cli/build/bin.js error Failed to build the app: No package name found. We couldn't parse the namespace from neither your build.gradle[.kts] file at /Users/username/Documents/projectname/android/app/build.gradle nor your package in the AndroidManifest at /Users/username/Documents/projectname/android/app/src/main/AndroidManifest.xml.

During RN update I followed react native upgrade helper instructions which guided me to remove package="my.app.bundle.android" property out of manifest object in src/main/AndroidManifest.xml file. Putting it back solved my issue.

jegor
  • 306
  • 2
  • 7
  • I faced the same problem. The solution was to use the correct node version in the react-native project. In my case it was Node 18. You have to check with exact version of RN are you using and which is the matching NodeJS version. I would bet on the latest Node LTS. – Heitara Aug 10 '23 at 09:22
0

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.

Cory Robinson
  • 4,616
  • 4
  • 36
  • 53
0

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.

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
  • downvotes are fine but it would be polite to offer some explanation? I can then attempt to improve the answer or remove it entirely. – Max MacLeod Dec 10 '19 at 10:08
  • Tested with 1.8.4 - clearly not caused by cocoapods version. Your build is nondeterministic. You had to change something else while upgrading or just assumed that "it just works!" with this version. – twboc Jan 02 '20 at 11:01
  • @twboc if you think it unrelated to cocoapods version you would have been unable to reproduce the error on both 1.5.2 and 1.8.4. Did you try 1.5.2? – Max MacLeod Jan 02 '20 at 11:21
  • OK but to be sure you need to try 1.5.2. – Max MacLeod Jan 02 '20 at 11:44
0

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.

Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148
0

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

Pods was looking for "Directory. "

Matthew Gruman
  • 191
  • 1
  • 5
0

maybe its related to rights issues

adding "@react-native-community/cli-platform-ios": "3.0.0" in package.json

and

sudo chown -R user .

worked for me

Mayur Shingare
  • 306
  • 2
  • 4
0

In my case I had to switch to a newer version of node.

mdehghani
  • 504
  • 1
  • 7
  • 23
0

Just delete Podfile.lock works. if you are facing issue even after all the answers. –

ppegu
  • 362
  • 2
  • 9
  • 22
0

Please check if this ios/chefzone.xcodeproj exists. In my case, this folder was deleted. then

yarn install, pod install, run it's working fine

-1

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

Vikas
  • 914
  • 7
  • 19
-1

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:

  • Changing Ruby Version
  • Changing CocoaPods version
  • Invalidating NPM and Cocoapods cache

And I am unable to fix the issue. It appears to be some npm dependency, but others on my team are not seeing it.

  • 1
    This is not an answer to the OP's question. – Umair Afzal Aug 13 '20 at 05:24
  • If the answers here do not solve your issue, please create a new question. Give a link to this Q&A, and explain what you have tried, and what happened. You will need to give more details: the complete error message, your podfile, and your package.json (because Cory Robinson's answer says he fixed by removing some older packages from his package.json). And of course delete any cache folders or lock files. – ToolmakerSteve Oct 21 '20 at 18:50
-2

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

-3

Go to this repository :ProjectName -> ios -> Podfile

  1. In the Podfile, delete use_native_modules!
  2. Execute again pod install
  3. Enjoy your new pod
netskink
  • 4,033
  • 2
  • 34
  • 46