13

I have just started out with React Native. I was following the React Native CLI Quickstart from the official documentation. That does also mean I am up to date with React Native version 0.61.2.

Since then I have done some basic UI, checking with the result in the iPhone simulator. It works when running react-native run-ios, not really touching the ios/Podfile too much.

My problem is running pod install inside my ios/ folder always results in an error! This becomes a problem now where I need to install additional packages. But it is already failing with default Podfile!

Error message:

[!] Invalid `Podfile` file: undefined method `[]' for nil:NilClass.

 #  from /Users/marcel/Projekte/WerBinIch/ios/Podfile:43
 #  -------------------------------------------
 #  
 >    use_native_modules!
 #  end
 #  -------------------------------------------

ios/Podfile

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'WerBinIch' do
  # Pods for WerBinIch
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  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-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  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 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  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 'WerBinIchTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

I have no idea how to deal with this! I have no idea how the Podfile and the thing with the xcode files really work! I was trying to delete folders accomplishing a reset. More than that I have no idea what the error message could mean.

Cutaraca
  • 2,069
  • 3
  • 14
  • 21
  • Possible duplicate of [react-native ios Podfile issue with "use\_native\_modules!"](https://stackoverflow.com/questions/56917963/react-native-ios-podfile-issue-with-use-native-modules) – Andrew Oct 17 '19 at 06:15
  • Thank you! The answer on that thread helped. I needed to install the npm package @react-native-community/cli-platform-ios. – Cutaraca Oct 20 '19 at 12:54

5 Answers5

11

This error happens when you cd to ios folder and run "pod install" and is because you added a new react native module by

npm -i package

instead of using yarn

yarn add package

To solve this problem, just go to the main react native project folder where package.json is and run the command below again

yarn cache clean

yarn add package

Then try cd to the ios folder and run "pod install" and there will no more errors. Hope this can help the other people who are also facing the same problem.

hengsok
  • 255
  • 3
  • 8
  • You are a savior. – Siraj Alam Jul 17 '20 at 16:21
  • 3
    I am not using yarn, just npm – Zeeshan Ahmad Khalil Mar 17 '21 at 04:51
  • 2
    @AbdulBasit sorry for late. You should delete the whole node_modules, Pods folder in ios folder, Podfile.lock and do "yarn" followed by 'cd ios', then 'pod install'. This is like cleaning everything and reinstall all modules and pods from scratch. Make sure you do not mix yarn and npm commands. Just use yarn, is easier and save the headache. – hengsok Jul 21 '21 at 05:16
4

This answer solve my problem well :

react-native ios Podfile issue with "use_native_modules!"

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 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!

mokagio
  • 16,391
  • 3
  • 51
  • 58
Lin. Irisa
  • 41
  • 1
  • Is it possible to not use require_relaitve "..." and instead use something like require_absolute ""? I desperately need this as my projects are going to sit into two different places – Shivam Sahil May 31 '22 at 05:38
2

after half of a day and try every solution, finally, I replace both

  • react-native
  • @react-native-community

folder from another RN 0.63 Project to node_modules and it's solved. maybe my cache was not deleted or replaced correctly.

2

In my case I accidentally created a package.json in my iOS folder. This seemed to confuse the react native build. I deleted the package.json in my ios folder, leaving the package.json in the root project folder and things worked.

aamirnshah
  • 59
  • 5
0
  • Add "@react-native-community/cli-platform-ios": "3.0.0" into your package.json file and run npm install in your main directory
  • Then cd ios and run pod install
  • Dont know why you are being downvoted, this solved my problem. Sure I might bump into something else now but the other answers did not work. – Ryan Knell Jul 22 '21 at 04:20