Cory Robinson
Cory Robinson

Reputation: 5262

react-native ios Podfile issue with "use_native_modules!"

In my react-native project ([email protected]) 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

Upvotes: 60

Views: 146382

Answers (30)

samuel luswata
samuel luswata

Reputation: 856

Delete node_modules
yarn cache clean
yarn install 
cd ios
pod install --repo-update

Upvotes: -1

Muhammad Saad Ansari
Muhammad Saad Ansari

Reputation: 1758

Alright, so nothing worked for me, but what worked for me is!

  1. Deleting these files and folders from your project directory as others have already mentioned.

    • Pods/
    • Podfile.lock
    • node_modules/
    • yarn.lock
    • ios/Build/
    • ios/Pods/
    • DerivedData/
  2. Use these commands to reset your Git repository and update everything:

    git reset HEAD~1 --hard    # Undo any local changes and go back one commit
    git pull                   # Get the latest code from your Git repository
    git clean -d -f -x         # Clean up any extra files and folders
    
    yarn                        # Install dependencies using Yarn
    cd ios && pod install       # Switch to the iOS directory and install CocoaPods dependencies
    

And boom... It worked!

Upvotes: 1

Bruno Pintos
Bruno Pintos

Reputation: 481

All the answers above didn't work for me. I had to restart my mac and then pod install worked, without changing anything else.

Upvotes: 0

Dmitry Minkovsky
Dmitry Minkovsky

Reputation: 38113

Be sure you have a newer version of Node. When I ran expo run:ios, I got the error from the question, but no useful debug information. But, when I did

$ cd ios
$ pod install

I got the error:

React Native needs Node.js >= 16. You're currently on version v15.14.0. Please upgrade Node.js to a supported version and try again.

After switching to a newer node with

$ nvm use 20

it all worked fine.

Upvotes: 1

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 81

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

Upvotes: 0

ppegu
ppegu

Reputation: 492

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

Upvotes: 0

Meabed
Meabed

Reputation: 3928

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!

Upvotes: 67

jegor
jegor

Reputation: 596

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.

Upvotes: 3

Isaac
Isaac

Reputation: 284

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 😬

Upvotes: 2

Daniel Danielecki
Daniel Danielecki

Reputation: 10502

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.

Upvotes: 1

mdehghani
mdehghani

Reputation: 551

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

Upvotes: 0

Utkarsh
Utkarsh

Reputation: 11

Steps to follow :

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

Upvotes: 1

Innocent TRA BI
Innocent TRA BI

Reputation: 63

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

Upvotes: -3

Kamil P
Kamil P

Reputation: 784

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.

Upvotes: 1

Arnav Nagpal
Arnav Nagpal

Reputation: 27

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

Upvotes: 1

Mayur Shingare
Mayur Shingare

Reputation: 306

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

Upvotes: 0

Doug Watkins
Doug Watkins

Reputation: 1438

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.

Upvotes: 2

Tyler Agnew
Tyler Agnew

Reputation: 93

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.

Upvotes: -1

Vitor Lopes
Vitor Lopes

Reputation: 111

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.

Upvotes: 11

Matthew Gruman
Matthew Gruman

Reputation: 309

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. "

Upvotes: 0

B. Mohammad
B. Mohammad

Reputation: 2464

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

Upvotes: 7

Jonas Sourlier
Jonas Sourlier

Reputation: 14435

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.

Upvotes: 0

Max MacLeod
Max MacLeod

Reputation: 26652

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.

Upvotes: 1

Naveen Raju
Naveen Raju

Reputation: 5791

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.

Upvotes: 3

jsina
jsina

Reputation: 4829

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.

Upvotes: 6

Vikas
Vikas

Reputation: 924

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

Upvotes: -1

MoOx
MoOx

Reputation: 8981

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

Upvotes: 6

ToniG
ToniG

Reputation: 41

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

Upvotes: 3

sean helvey
sean helvey

Reputation: 27

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 [email protected]

Upvotes: -2

Cory Robinson
Cory Robinson

Reputation: 5262

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.

Upvotes: 0

Related Questions