'PhaseScriptExecution error in React Native app

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.



Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

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.

Solution 4:[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)

Solution 5:[5]

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.

Solution 6:[6]

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

Solution 7:[7]

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)

Solution 8:[8]

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/

Solution 9:[9]

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

Solution 10:[10]

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

Solution 11:[11]

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

Solution 12:[12]

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