68

While executing npx react-native init MyProject I ran into the following error:

✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.

Which seems to be related to an earlier error displayed:

checking for arm-apple-darwin-gcc... /Library/Developer/CommandLineTools/usr/bin/cc -arch armv7 -isysroot 
checking whether the C compiler works... no
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'Path' in SDK 'iphoneos'

XCode and its CLI seem to all run fine.

My configuration:

  • MacOS Catalina 10.15.1 (19B88)
  • NPM 6.11.3
  • React-Native 0.61.4
  • XCode 11.2.1 (11B500)

Any leads appreciated.

Vaiden
  • 15,728
  • 7
  • 61
  • 91

25 Answers25

92

I've found a very similar error reported here, with a solution that suggested:

sudo xcode-select --switch /Applications/Xcode.app

Reading around seems to suggest that somewhere down the updates line, the XCode CLI tools path was set to an incorrect one.

Also as @bibin-jaimon suggested in the comments below, I do have multiple versions of XCode on my machine (why? because of https://stackoverflow.com/a/58329901/606351).

Anyways, problem solved.

Vaiden
  • 15,728
  • 7
  • 61
  • 91
  • 1
    The same problem happens if your mac contains two version of Xcode. – Bibin Jaimon Jan 11 '20 at 18:02
  • OK - Then this might have been the issue in my case. Thanks for sharing! – Vaiden Jan 12 '20 at 09:17
  • 3
    I didn't have 2 Xcode versions but still experienced this on a fresh computer setup. This sorted it – scgough Jan 19 '20 at 13:05
  • this worked for me. Perform this step if you are trying to setup react native and Xcode in a new Mac. – Charith Nidarsha Oct 19 '20 at 06:09
  • 1
    Worked for me. I think the reason for me was that I installed react native on my mac first, then xcode. That messed up the path – jsog Oct 24 '20 at 17:17
  • For me, I didn't accepted the Xcode's EULA. I just installed it and tried to create a new rn project – Andre Ravazzi Mar 03 '21 at 00:09
  • Worked for me. Thanks! Had a fresh install of xcode and hence, was facing this problem. – Dhruv Godara Apr 18 '21 at 03:53
  • If xcode-select tells you `xcode-select: error: invalid developer directory '/Applications/Xcode.app’` there’s a good chance you didn’t actually install Xcode :-) – Paul Aug 10 '21 at 10:17
  • Where did you run this command? I am currently inside of my project folder, but I don't believe that is the right area. – Kehlin Swain Sep 12 '22 at 01:15
  • @KehlinSwain - anywhere. This command fixes the symlink to the xcode app: https://stackoverflow.com/questions/14609738/where-does-xcode-select-store-information – Vaiden Sep 14 '22 at 09:21
51

Unfortunately the selected answer didn't work for me. I have Mac OS Catalina 10.15.4, and I have latest version of xcode Version 11.0 (11A420a). I found some suggestions to reinstall cocopods using homebrew or gem, and at first it didn't work for me, but using it as in below command worked perfectly.

sudo gem install cocoapods -n /usr/local/bin
Jason G
  • 2,395
  • 2
  • 24
  • 34
A Khudairy
  • 1,422
  • 1
  • 15
  • 26
  • 4
    You have saved my day! – Helio Soares Junior Jun 14 '20 at 23:05
  • 1
    The @Vaiden solution not work for me also, so, I try you answer but then, it give-me a direction with the returned error msg, so, first: I updated Xcode, but, not has updated xcode-select; second: with xcode-select updated, I got the version conflict in cocoapods, so, based in this new error msg I solved my problem here, using this [solution](https://stackoverflow.com/questions/20939568/error-error-installing-cocoapods-error-failed-to-build-gem-native-extension), thanks to **Jigar Thakkar**. – Armando Marques da S Sobrinho Mar 15 '21 at 19:51
  • Glad you got it :) – A Khudairy Mar 16 '21 at 16:41
13

Ali Shirazee's solution worked well for me (thanks!).

After running:

npx react-native init myAppName --template react-native-template-typescript

I got the error:

error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./myAppName/ios && pod install". CocoaPods documentation: https://cocoapods.org/

Then I went into the folder and ran pod install as suggested in the error message but still got an error during the installation of Flipper-Glog.

Finally, I've opened Xcode, went into Preferences » Location and selected Xcode 11 from the Command Line Tools select list.

Xcode » Preferences » Location
Xcode » Preferences » Location

After that, I simply ran pod install again and it all worked.

de.
  • 7,068
  • 3
  • 40
  • 69
Renan
  • 131
  • 1
  • 4
  • 1
    Had the same problem with `Flipper-Glog`, Doing `sudo xcode-select --switch /Applications/Xcode.app` seems to work like Vaiden suggested in this thread the xcode selection might boil down to this as well – Darsh Patel Mar 17 '21 at 14:31
13

I had this issue because I got a new M1 mac, and I found a solution based on this github issue answer and this stackoverflow answer

Everything seemed to start working when I installed the ffi gem with the terminal running in Rosetta

vancy-pants
  • 1,070
  • 12
  • 13
  • 3
    thanks. as per the above stack over link, the below commands helped me sudo arch -x86_64 gem install ffi arch -x86_64 pod install ( inside the project/ios folder) – Raghu Vallikkat Mar 20 '21 at 06:28
  • i followed the answer links and right now pod install is running fine. but I have a question which is "Do I again need to do react-native init for project initialisation or is it done already?" Please confirm on this – amit pandya Oct 14 '22 at 06:49
9

I resolved this issue,

The situation with me was I recently bought a new mac and installed Xcode along with my development environment.

However I forgot to configure the Xcode command line tools, when I resolved it worked fine.

so follow these simple steps (refer to the screen shot).

Xcode > Preferences > Locations

on the command line tools select the option, in my case it was Xcode 11.7 (11....)

please note that i had deleted and reinstalled brew, cocoapods and node and it did not work until configured Xcode.

please refer to the screenshot.

then run sudo npx react-native init yourProjectName

enter image description here

Ali Shirazee
  • 1,008
  • 10
  • 11
8

What worked for me on my Mac M1 machine was:

Before hand, download Xcode.

First: I went to the Applications through Finder and clicked into the Utilities folder. Inside the folder, I right clicked the Terminal icon and clicked Get Info from the popup. After, another popup should have appeared and I checked the box, Open using Rosetta.

Next, I did the same with Xcode. I went into the Applications folder, right clicked the Xcode icon, and checked Open using Rosetta

After I went into the terminal and copied in these commands:

sudo gem install cocoapods

Finally,

sudo gem install ffi

Afterwards I ran:

npx react-native init HelloRN

And I did not get an error.

Hopes this helps!

jadonlamx
  • 81
  • 1
  • 2
6

Update repo then reinstall:

$ pod repo update
$ pod install
ufukomer
  • 1,021
  • 1
  • 14
  • 16
  • 1
    Of all the answers here, this is the one that worked for me. By the way, there's a typo: **install** – Beer Me Apr 13 '21 at 19:24
4

In my case, the link between homebrew and cocoapods had broken I'm guessing during the catalina upgrade.

Following command fixed it: brew link --overwrite cocoapods

James Cullis
  • 291
  • 1
  • 7
3

In my case, the problem was because I haven't cocoapods installed.

brew install cocoapods

This solved my problem.

moigamijunior
  • 85
  • 1
  • 7
2

For myself non of the above worked apart from this one which seemed to install a lot of missing Flipper kits and some other missing dependencies -

 pod install --repo-update
walker1
  • 341
  • 1
  • 5
  • 18
2

"brew install cocoapods" worked for me. I'am using M1 14"

1

This was also not working for me. I have tried every answer given in this thread and none of them worked for me. I was trying on Intel Mac not the Apple Silicon Mac

If similar thing happens to anyone else then try this.

sudo gem install cocoapods
Pawan Sharma
  • 3,199
  • 1
  • 25
  • 32
1

Make sure you don't have empty space in any folder names leading to your project directory (example 'My Documents'). Its simple, but this is how i fixed the error.

Husky931
  • 636
  • 6
  • 10
1

in my case, I just cd into ios in my project folder and run bundle install

Iggy_code
  • 19
  • 3
1

make sure you are not using the Ruby that the system is operating.

ruby is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installs another version in parallel can cause all kinds of trouble.

so you need to install ruby for example with homebrew:

  • run
brew install ruby 
  • If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
  • For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib" >> ~/.zshrc
  export CPPFLAGS="-I/usr/local/opt/ruby/include" >> ~/.zshrc
  • then install cocoa pods by running gem:
sudo gem install -n /usr/local/bin cocoapods
Amir
  • 349
  • 3
  • 4
0

After using the command from the selected message, I got the following error:

[!] Error installing Flipper-PeerTalk
[!] /usr/bin/git clone https://github.com/priteshrnandgaonkar/peertalk.git /var/folders/hw/0fc3vqbn4t34rk73tk1r9lwr0000gn/T/d20201016-18847-1n36woh --template= --single-branch --depth 1 --branch v0.0.3

Cloning into '/var/folders/hw/0fc3vqbn4t34rk73tk1r9lwr0000gn/T/d20201016-18847-1n36woh'...
fatal: unable to access 'https://github.com/priteshrnandgaonkar/peertalk.git/': Could not resolve host: github.com

Then I used A Khudairy's solution and it worked very well. Thanks for everyone.

(Just reporting this because, maybe, someone can find this new error on this process and now this page can be googled with this solution)

allanmelo
  • 11
  • 4
0

It gave me the same error and also said:

*Please try again manually: "cd ./myApp/ios && pod install"* 

which I did. It turned out that my CocoaPods version is below the required version. Your problem could also be this.

*[!] `React` requires CocoaPods version `>= 1.10.1`, which is not satisfied by your current version, `1.9.1`.*

Then i upgraded the Cocoapods by:

brew upgrade cocoapods
tidalwave
  • 186
  • 1
  • 5
0

finally, for my case, it can work by:

  1. Try to open up Xcode, and it will ask to install the required dependencies/component for it to work (usually due to some update)
  2. Install / Reinstall Cocoapods, type sudo gem install cocoapods
  3. Try npx react-native init AwesomeProject hopefully it works :)
0

Removing environment variable LDFLAGS and CPPFLAGS in ~/.bashrc or ~/.zshrc solve it for me.

Then in terminal use source ~/.bashrc or source ~/.zshrc to make those changes in the terminal session.

ajmccall
  • 2,024
  • 23
  • 42
0

WARNING: pod update is dangerous because you'd update all of your dependencies to the latest version

For me doing pod update instead of pod install worked!

I was getting an error with Flipper-Glog

CocoaPods could not find compatible versions for pod "Flipper-Glog": In Podfile: Flipper-Glog (= 0.5.0.4)

Running pod install manually after the npx react-native init failed to install was not working so I added pod update and it installed not only Flipper-Glog but also all the others successfully.

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
  • _pod update_ is dangerous because you'd update *all* of your dependencies to the *latest version* that fits the criteria in your Podfile: https://guides.cocoapods.org/using/pod-install-vs-update.html – Vaiden Apr 04 '22 at 08:27
0

I have tried above all possible solution but failed:

then i made some changes and it worked perfectly.

just goto project/ios/podfile

open podfile and add bellow line

use_flipper!() --> just underneath/below to this line

use_flipper!({'Flipper' => '0.125.0'}) --> // you need to add this line

or

you can get help from this link below

https://fbflipper.com/docs/getting-started/react-native-ios/

sherkhan
  • 811
  • 8
  • 8
0

i had similar problem . the solution that worked for updating the pod

pod repo update

then ran

pod install

it gave a waring on mac m1 and worked ok.

 Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64)
Nahid Hasan
  • 687
  • 1
  • 10
  • 34
0

If you are using Apple silicons

first run sudo gem uninstall cocoapods and then run brew install cocoapods

make sure you have homebrew https://brew.sh/

0

If you already have the latest version of CocoaPods installed, try running pod install again. If the issue persists, try running pod install --repo-update.

cd ios

pod install --repo-update
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

sudo gem install activesupport -v 6.1.7.4

you can write install your gem version as well.

Thanks