52

Facing this error when I run react-native run-ios after creating the project

Error -

error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening BoltAssignment.xcworkspace.
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace BoltAssignment.xcworkspace -configuration Debug -scheme BoltAssignment -destination id=3E598855-6D4F-4F36-BEE1-8663A1F71787


nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
Command PhaseScriptExecution failed with a nonzero exit code

warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flipper-Glog' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.4, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flipper-PeerTalk' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'libwebp' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'YogaKit' from project 'Pods')
warning: Capabilities for Signing & Capabilities may not function correctly because its entitlements use a placeholder team ID. To resolve this, select a development team in the BoltAssignment editor. (in target 'BoltAssignment' from project 'BoltAssignment')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flipper-DoubleConversion' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'boost-for-react-native' from project 'Pods')
warning: no rule to process file '/Users/harsh_nagalla/dev/BoltAssignment/ios/Pods/Flipper-RSocket/rsocket/README.md' of type 'net.daringfireball.markdown' for architecture 'x86_64' (in target 'Flipper-RSocket' from project 'Pods')
warning: no rule to process file '/Users/harsh_nagalla/dev/BoltAssignment/ios/Pods/Flipper-RSocket/rsocket/benchmarks/CMakeLists.txt' of type 'text' for architecture 'x86_64' (in target 'Flipper-RSocket' from project 'Pods')
warning: no rule to process file '/Users/harsh_nagalla/dev/BoltAssignment/ios/Pods/Flipper-RSocket/rsocket/benchmarks/README.md' of type 'net.daringfireball.markdown' for architecture 'x86_64' (in target 'Flipper-RSocket' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'RNFastImage' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'SDWebImageWebPCoder' from project 'Pods')

** BUILD FAILED **


The following build commands failed:
    PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/harsh_nagalla/Library/Developer/Xcode/DerivedData/BoltAssignment-cxeqsscopunscndrzxcrfnugkasb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-1F0D93C9412E4439D9C46216EB143B15.sh
(1 failure)

Steps followed-

  1. yarn install
  2. start metro server
  3. cd ios -> pod install
  4. npx react-native run-ios

Pretty new to react native so I am totally clueless why this is happening. It would be much appreciated if someone can help with this.

If you have faced the same issue and still clueless like me then please share and upvote so it reaches to as many people as possible.

Harsh Nagalla
  • 1,198
  • 5
  • 14
  • 26
  • 4
    Having the same issue. Surprisingly it works fine in my other Mac. I checked pods, node, yarn versions and they are all the same. Opening the .xcworkspace file inside /ios/ folder with Xcode and building from it works fine for me. – Sergio Diez Mar 14 '21 at 20:50
  • 2
    @SergioDiez yes I am in the same situation very bizarre – Harsh Nagalla Mar 14 '21 at 23:59
  • 9
    Having the exact same issue after upgrading to 0.64.0. – Hyo Mar 15 '21 at 03:56
  • 4
    I'm having the same problem, it seems to be an nvm problem, as when I open xcode the app builds fine. – Mush Mar 15 '21 at 11:11
  • 1
    I was having problems building the app and I've realized that I was using `yarn ios` once I used `npx react-native run-ios` the app built successfully. – Mush Mar 16 '21 at 22:28
  • 1
    Had the exact same issue. If I installed node via nvm it produced this error. I had to remove nvm/node and install it via homebrew. Not ideal – sooper Mar 25 '21 at 20:57
  • @sooper Thats kinda weird shouldn't happen because of the way node is installed. – Harsh Nagalla Mar 26 '21 at 05:30

15 Answers15

64

I have figured out a solution, if you're using nvm make sure you don't have another globally installed version of Node/npm.

If you aren't sure whether or not you have a global version, go to your bash_profile/zshrc and comment the three nvm initialization lines (export NVM_DIR="$HOME/.nvm" [...]), then open a new terminal and do node --version, if it still finds something it means that you have a global version somewhere, and you can find its path with which node.

In my case I'm using Homebrew, and I had a global version of Node that I wasn't even aware coming from the yarn formula, I discovered it after running brew uses --installed node. I went ahead and uninstalled yarn using brew uninstall --force yarn, which automatically uninstalled its node/npm dependency, then uncommented the nvm initialization lines, and then I reinstalled yarn using nvm's npm with npm i -g yarn, and now everything works.

Edmundo Santos
  • 8,006
  • 3
  • 28
  • 38
  • 1
    Wow, no idea how you figured this out but this solved it for after weeks of headaches and terrible workarounds. Thank you! – Brady Dowling Nov 01 '21 at 17:19
  • I somehow had `unset PREFIX` in my `.zshrc`. Your solution + removing that line did it for me (after months using the workaround to start RN project from XCode instead) – Andru Nov 13 '21 at 22:37
  • Yeah, so using yarn via homebrew seemed to be my issue, as you mentioned. Removing that and installing via nvm's npm instead sorted it for me. Thanks for this – lee_mcmullen Apr 05 '22 at 21:21
  • even after disabling nvm, the nvm command wouldn't work anymore, though `which node` still returns an nvm path and `node -v` also works, no idea how `node` still works, also checked, no node installed via `brew` (which should also use another path) – Can Rau Apr 22 '22 at 00:37
  • Excellent answer. I'll add that I had to run `nvm use __` again after removing yarn/node that was installed from homebrew before my project recognized node managed by nvm. – codejays May 08 '22 at 04:01
  • 1
    I installed node through `nvm`. I do not have any other conflicting version of node. Yet, none of these suggestions work for me. So, sadly, it's not a universal solution. – Mike S. Aug 11 '22 at 15:12
16

The only solution that worked for me currently (RN v0.64.0), till this issue root cause properly identified (seems related to nvm though!) is to go to your /node_modules/react-native/scripts/find-node.sh and set these two lines on top.

You can use patch-package to keep those changes permanent.

unset npm_config_prefix
unset PREFIX
Solly
  • 496
  • 1
  • 6
  • 14
10

I was facing the same error, and I've just run the command suggested in the error:

$ unset PREFIX.

Afterwards the app was building properly.

Cata Mates
  • 101
  • 3
4

On Mac, using these two steps, I resolved the issue.

  1. I have removed the old ~/.nvm folder. from-comment
  2. Then I have created via command ln -s $(which node) /usr/local/bin/node (from-answer)
Muhammad Maqsood
  • 1,622
  • 19
  • 25
2

Got same error. Tried lots of fixes, but nothing helped. I fixed this problem by creating new user on my mac. IOS app began building again in Xcode. I will make some more research what was the reason. I guess its because of bad development environmet setup.

Villar
  • 63
  • 5
2

If you explicitly know what version of node you want to run, there's a way to inject it without patch-package (or, one rabbit-hole I went down, sed). The find-node.sh script is actually just updating the PATHs that node is looked for, where generate-specs.sh is actually looking for the node binary...but it allows you to override that with the NODE_BINARY environment variable.

So you could NODE_BINARY=/usr/local/bin/mynode npx react-native run-ios

Kaolin Fire
  • 2,521
  • 28
  • 43
1

React Native 0.64 uses the new codegen part and this does not work correctly (yet) when there are spaces in the path of the project. It's a know bug and will be solved in future version, PR already is made

For now you could use a path without a space in it.

Works

/home/wbroek/projectname/

Does not work

/home/wbroek/project name/
wbroek
  • 53
  • 3
  • But, in the original reporter's error message, there does not appear to be a problem with spaces at all. There may *also* be a problem with spaces, but I don't see how your answer relates to the poster's problem? Or am I missing something? I could be! – Mike Hardy Mar 15 '21 at 19:34
  • Yeah, My path doesn’t have any space and I still get this error, and I think Harsh’s neither as we can see in the log. – Sergio Diez Mar 15 '21 at 20:41
1

I had the same issue, the fastest way for it to work (due to some professional issues) was to completely remove NVM and installing Node through brew (macOS)

Iuji Ujisato
  • 98
  • 1
  • 8
1

Solution

The following contains a guide of 17 steps on how to install React Native on your Mac OS for iOS development. Before starting the installation process, it is important to read the guide carefully and avoid rushing through it. Taking the time to fully understand the steps will save you time and effort, and prevent frustration with React Native installation and running process.

Start: To begin, it's important to define your goal. In this case, my goal is to install React Native on my environment without breaking any existing projects, specifically an outdated enterprise React project that I have. This means that I want a fresh installation of the React Native CLI (not Expo) on your Mac OS, specifically for iOS development. This is exactly what I select in tabs here. (https://reactnative.dev/docs/environment-setup)

To sum up: I want my outdated enterprise react project to continue working. So I do not break anything work related.

I want a fresh React Native CLI installation(not Expo) on Mac Os for iOS. (this is what you select in Tabs at this https://reactnative.dev/docs/environment-setup )

I want the latest version of react native. The current latest version is 0.71

Current system setup. It's important to understand your current system setup. In my case, I have:

Node Version Manager (NVM) is being used to switch between node versions. This is a proper way of installing Node, since you may need different versions for different projects. Indeed, React Native docs cover the setup of a global node version, which is not what we want!

The computer being used is a Mac Air, not an M1. This is important to note due to M1 Macs having different system requirements for some software and may require additional steps for installation.

iTerm is the terminal being used on the zsh command line.

Setup

First read it all, and start only after reading. Do not follow the guide on the react native setup, especially as for ruby installation and node installation. Read the following text first carefully. If you do a part of that and then a part from somewhere else, your project may not run and will prolong your struggle.

Step 1. Install Brew if you have not installed it. https://brew.sh/

Step 2. Install watchman if you have not installed it:

brew install watchman

Step 3. Do not install node globally, as this guide assumes you are using NVM to switch between Node versions.

Step 4. Switch Node to the proper version. I used version 18.13.0 to make it work. Make the node to be the default one and select it. For that open your terminal and run:

nvm alias default 18.13.0
nvm use default

if you do not have the node of this version installed, install it first. To install NVM, follow the NVM installation guides.

nvm install 18.13.0
nvm alias default 18.13.0
nvm use default

Every time you want to use another node you may change the default as you want.

Step 5. Install proper version of Ruby. React documentation for version 0.71 says:

"Currently, macOS 13.2 is shipped with Ruby 2.6.10, which is not what is required by this version of React Native (2.7.6)."

That is what I had. The Ruby version for me was - 2.6.10. I need 2.7.6. There is a tool, which is similar to NVM but for Ruby. React gives the list of libraries to manage Ruby versions. I selected rbenv (https://github.com/rbenv/rbenv).

Follow the installation of rbenv on your system. Do not rush. Read everything. After installation it contains the command to be run in the terminal as for ZSH. So make sure you did everything correctly, and run the command for the terminal you use. (Remember, iTerm is a terminal client) After you installed rbenv check what versions of ruby you have on your system. Run in your terminal:

rbenv versions

We need ruby 2.7.6, so if you do not have it - install it

rbenv install 2.7.6

After the installation you need to switch to version 2.7.6. Exactly like with the node.

rbenv global 2.7.6

Step 6. Now go to this chapter called "Xcode" in react native setup guide and do everything as they say here https://reactnative.dev/docs/environment-setup#xcode. Do what is in "Xcode" chapter and proceed until “Creating a new application” chapter and stop there.

Step 7. Open the terminal and navigate to the folder where your new react native project will be located. From here, react says we do not have to have global CLI installations, so we need to remove them to avoid conflicts when running scripts. I did that.

npm uninstall -g react-native-cli @react-native-community/cli

To check if you have any of those installed globally use:

npm list -g react-native-cli 
npm list -g @react-native-community/cli

Step 8. Create a new fresh install. Before running, check that you have all the proper versions installed and selected.

node -v          (you should see v18.13.0)
rbenv versions   (you should see the list with "* 2.7.6")

After that run:

npx react-native@latest init AwesomeProject

That must go with our errors. It will create a new folder named AwesomeProject. Go into it:

cd AwesomeProject

Running the project. The project is installed, now we will run it.

Step 9. Kill all processes that may be related to the metro server. The first command will scan what takes the port 8081. If nothing is returned in the console you are good to proceed. If you see the list of processes - kill them with:

sudo lsof -i :8081
kill -9 <PID>

Step 10. Now, if you have several projects, like I do, Xcode may start looking for another Pod file. To make sure, Xcode while building the app uses the correct Pod file. For that do the following:

Create a new file "react-native.config.js" in root of your project folder "AwesomeProject/" and put into it:

module.exports = {
  project: {
    ios: {
      sourceDir: './ios',
    },
  },
};

Make sure you saved the file and when you copied the quotes are not changed to be invalid quotes for the file. So the file is still in a proper format.

What we did, is that now react native will track the Podfile that we have in the project "/ios" folder.

React Native uses CocoaPods, or simply Pod, as a dependency manager for iOS projects. CocoaPods is a popular dependency manager for Swift and Objective-C Cocoa projects and allows for easy integration of third-party libraries.

In the context of React Native, CocoaPods is used to manage dependencies for React Native projects that are built for iOS. When you create a new React Native project for iOS, it generates an Xcode project that includes a Podfile. The Podfile lists all the dependencies that the React Native project requires to function properly, such as the React Native framework itself.

Step 11. Now, we must say that we are using Node of a specific version.

For the react 0.71 it is not enough to change the default version! (insane)

So, If you are using nvm you need to specify the path to the node version.

To do that open a file "ios/.xcode.env" in the code editor. You will see several lines of comments and the line to the end:

export NODE_BINARY=$(command -v node)

Instead of "$(command -v node)" place the path to your selected node version there.

  1. Get the full path to your node installed with nvm. Run in terminal:

    which node

Copy the path, and instead of what is assigned to NODE_BINARY put your path. You must have something similar to this:

export NODE_BINARY=/Users/your_user_name/.nvm/versions/node/v18.13.0/bin/node

Make sure you saved the file.

Step 12. Now we need to Sign the project with the certificate. Go to "/ios" folder and open the ".xcworkspace" file. It is name “AwesomeProject.xcworkspace” and wait till Xcode opens.

When it opens, in the left side bar select the project - AwesomeProject, then you will see two Targets to the left of the central panel of the screen. Select your project AwesomeProject by clicking it. In the centre of the screen select the “Signing & Capabilities” tab. Select the proper team from the dropdown. That is the vital step. If something is not good, then you will get the error in xcode and while building phase.

This is where I had a problem. I have 2 teams. One is my work related team, and the other one is called My Personal team. I do not remember when I created “My Personal team”, but I selected it,as it was not related to my work. Project build failed. When I switched to my working team, it started to build without errors. So make sure you know that what you select is legit and it does work.

Make sure you set your new Bundle Id where you see the appropriate field for it. E.g. "com.mylastnam.myappid"

Step 13. Select another Target - AwesomeProjectTests and do the same signings as in the Step 12.

Step 14. On top of the screen Select your simulator you want the project to be built. But do not run or build the project. If you do not have any simulators, add them first, and you will see them in the list.

Step 15. Get back to your terminal. Go inside the project folder and run:

npx react-native start

You will see the metro server running. It runs on port 8081, that’s why we killed all the processes that possibly occupy that port.

Step 16. Open a new tab in the terminal, navigate to your project folder and run: Note: specify the simulator name you selected in step 14.

npx react-native run-ios --simulator="iPhone 13 Pro"

Now brace yourself and wait till you see the simulator started and it will install the new application for you.

Step 17. If you see the error like on the screenshot below, do the following steps.

enter image description here

Open "node_modules/react-native/scripts/" in Finder (open node_modules/react-native/scripts/)

Right-Click on launchPackager.command and click Open With then choose Other... ---> Select your terminal application. I selected iTerm.

In your Applications directory, select iTerm and click Always Open With You are done. You will see the application running in your simulator in a hot reload mode.

Conclusion:

  1. It looks completely overkilling and it really is.
  2. I followed all the steps above after I wrote this, to make sure it does work - and it does.
  3. I am disappointed by React for not providing the section of installation in case you are using NVM.

Let me know if it helped you.

Pavlo Savchuk
  • 167
  • 1
  • 5
0

It´s a bit of a hack but try this in your podfile: Ref

post_install do |installer|
installer.pods_project.targets.each do |target|
  if (target.name&.eql?('FBReactNativeSpec'))
    target.build_phases.each do |build_phase|
      if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
        target.build_phases.move(build_phase, 0)
      end
    end
  end
end
0

I have also faced a similar type of issue. I have find solution on react native github repo.

Removing

export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion from ~/.bash_profile .

AND

Commenting out all the code from project/node_modules/react-native/scripts/find-node.sh helped to solve this issue.

You can also check original https://github.com/facebook/react-native/issues/31249#issuecomment-811715288

Vishal Dhanotiya
  • 2,512
  • 1
  • 13
  • 32
0

I had this problem while my which node was pointing to /usr/local/bin/node

Solved it by

  1. Installing nvm from curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  2. nvm use 16
  3. cd ios/ Delete podfile.lock and Pods/
  4. pod instal
-1

I had a same problem and could solve it as following steps.

  1. {your project} > ios > Podfile

Change from "false" to "true" at the "hermes_enabled" setting.

:hermes_enabled => true
  1. cd ios && pod install

  2. npx react-native run-ios

-3

I solved this problem using npx react-native run-ios instead of yarn ios.

Maybe can help u .

-6

Yeah, had the same issue, didn't realize it was a new RN version first. Downgraded to 0.63.4 and it works as it should:

yarn upgrade react-native@0.63