44

when I have a react native project....and when I run pod install it gives me the following error

Invalid `Podfile` file: cannot load such file -- /myPath/node_modules/react-native/scripts/react_native_pods

Here is my podfile

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

platform :ios, '10.0'

target 'xs' do
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])

  target 'xsTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  use_flipper!
  post_install do |installer|
    flipper_post_install(installer)
  end
end

target 'xs-tvOS' do
  # Pods for xs-tvOS

  target 'xs-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

Ive checked and there is no file called react_native_pods in location myPath/node_modules/react-native/scripts/. Im wondering if its something to do with npm install is not generating correct files.....however I upgraded node to most recent version and then ran npm install

james murphy
  • 1,505
  • 5
  • 31
  • 57

16 Answers16

51

I ran npm audit fix and it added react_native_pods file and pod install then worked

james murphy
  • 1,505
  • 5
  • 31
  • 57
  • 8
    Thanks, this helped identify some errors in the `package-lock.json` file. I had to run `npm install` to fix it, after which `pod install` worked. – StoriKnow Oct 30 '20 at 17:37
  • Wow amazing! Anyone knows why this works? – Jarrett Mar 05 '21 at 03:08
  • @Jarrett you run npm install first, because you need to install node specific things first, after that you can run pod install, and according to [docs](https://docs.npmjs.com/cli/v7/commands/npm-audit) npm audit fix runs npm install under the hood – Mod3rnx Mar 11 '21 at 14:07
  • `react-native-pod` (not pods) – Sid Nov 25 '22 at 05:18
16

Run npm audit fix ==> cd ios ==> pod install

Vishesh Gupta
  • 165
  • 1
  • 5
16

If npm audit fix is not working for you then try below solution.

- sudo gem install cocoapods
- npm i
- cd ios
- pod install
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
13

It can also be that you just forgot to run yarn / npm before running pod install.

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

I have meet the same error, solved by upgrade the version of React Native from 0.62 to 0.63, it works for me Because of the file react_native_pods does't exists in the folder scripts when the version is 0.62, It appears when I upgraded the version of RN to 0.63, after npm install , It works when pod install, hope it would help other who encounter the same error

RiversRen
  • 41
  • 1
4

I just did npm install before running pod install and it solved for me.

jyotishman saikia
  • 2,079
  • 1
  • 15
  • 11
3

In my case Ive deleted yarn.lock, podfile.lock and it worked fine after yarn and pod install again

Esteban
  • 41
  • 1
3

Make sure you've installed your npm dependencies.

Run following command and then install pods.

  1. To install npm packages:
yarn install
  1. And then, remove old pod cache:
cd ios && pod deintegrate && rm -rf Podfile.lock
  1. To update pods and start ios:
pod install --repo-update && cd .. && react-native run-ios
Bek Roz
  • 658
  • 7
  • 10
1

in order to fix this: what i did is:

  1. react-native upgrade: It mainly upgrades react-native version, which will also upgrade some of your ios files such as Podfile amongst other things.

Try if this works for you or not. You can also create a latest react native project and compare your files/directories using "Beyond compare", also you need to rename some lines in your files.

Also read the comments in files for better understanding.

ArefinDe
  • 678
  • 7
  • 13
1

This wroked for me:

cd ios
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

Via this link.

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
1

I had this error in 2022 and this was the most relevant search result and didn't fix it.. so in case anyone else out there is running into this, I fought this for days and finally fixed it by:

Creating a brand new directory by: expo init new-project and then copy over your .js files, screens, and assets etc. Do this by hand, don't copy any of your lock files or node-modules or anything else. Just the files that you created/touched yourself. Then expo start. Load the project on your mobile / simulator and when it fails with a module requirement missing add it individually. Repeat this start-error-add until the build succeeds. This was the only way I found to get it working.

1

In my case, I installed cocoapods from brew and gem

Based on the latest react-native documents, you will need to install it from gem

Do the following steps:

  1. sudo brew uninstall cocoapods to remove cocoapods install via brew
  2. sudo gem uninstall cocoapods to remove cocoapods installed via gem

Finally

  1. sudo gem install cocoapods to install the latest version via gem
Hamed Navabian
  • 720
  • 7
  • 11
0

Yarn cd ios pod install

Works for me

Rana sami
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 13 '22 at 22:04
0

just install,

@react-native-community/cli-platform-ios

in package.json

then yarn install in your root and cd ios and also arch -x86_64 pod install

-1

verify that you have a node_modules folder, I was missing that

Kingsley Akpan
  • 213
  • 3
  • 3
-1

Go and add react-native.pods.rb file inside of Node_Module->React-Native->Scripts->(add here)

Rishabh
  • 19
  • 1