skip to Main Content

I’ve been struggling with this error, it happened a week ago when I switched to new machine. Below is my machine config -> node, npm, yarn etc:

node --version -> v16.18.1
which node -> /opt/homebrew/opt/node@16/bin/node
which npm -> /opt/homebrew/opt/node@16/bin/npm
which yarn -> /opt/homebrew/bin/yarn

I also have nvm installed. Could this be happening due to yarn not pointing to where the node is installed? as the directory differs.

Then I tried to uninstall yarn using npm uninstall -g yarn & re-install it again using npm install -g yarn and go into my project, deleted node-modules, re-installed pods and everything but still this error persist.

I went through these solutions and none of them really worked out for me -> PhaseScriptExecution [CP-User] error in React Native

Below is the build error that I’m getting:

/bin/sh -c /Users/username/Library/Developer/Xcode/DerivedData/project-bqzfnxmekpsgkmfaztyrfllaudqg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00047A70.sh
Node found at: /opt/homebrew/Cellar/node/19.0.1/bin/node

/Users/username/Desktop/project/ios/Pods/../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/react_native_pods_utils/script_phases.sh: line 83: /opt/homebrew/Cellar/node/19.0.1/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

** BUILD FAILED **


The following build commands failed:
    PhaseScriptExecution [CP-User] Generate Specs /Users/username/Library/Developer/Xcode/DerivedData/project-bqzfnxmekpsgkmfaztyrfllaudqg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00047A70.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)

/.zshrc :-

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
export PATH="/opt/homebrew/bin:$PATH"
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/ndk/21.4.7075529
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="/opt/homebrew/opt/node@16/bin:$PATH"

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"

As I said it looks like when I do yarn install inside my project folder, as yarn is not pointing to the node installation directory, it may be considering the wrong version and downloading with wrong version and so this error arises…

Can someone help me with this issue?

Thanks in advance!

EDIT-1

This is my find-node-for-xcode.sh under node_modules/react-native/scripts/

#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set -e

# WHY WE NEED THIS:
# This script is used to find a valid instance of `node` installed in the machine.
# This script is sourced by other scripts to get access to node.
# Specifically, it is used by the `react-native-xcode.sh` script, invoked by a
# post-build phase in Xcode, to build the js files required by React Native.
#
# DEPRECATION NOTE:
# React Native should not make assumptions on your current node environment.
# This file is deprecated and will be removed in a future release in favor of something
# node-agnostic and configurable by the developers.

# remove global prefix if it's already set
# the running shell process will choose a node binary and a global package directory breaks version managers
unset PREFIX

# Support Homebrew on M1
HOMEBREW_M1_BIN=/opt/homebrew/bin
if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
  export PATH="$HOMEBREW_M1_BIN:$PATH"
fi

# Define NVM_DIR and source the nvm.sh setup script
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc
# See: https://github.com/nvm-sh/nvm/issues/2053
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$HOME/.nvm/nvm.sh" --no-use
  nvm use 2> /dev/null || nvm use default
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$(brew --prefix nvm)/nvm.sh" --no-use
  nvm use 2> /dev/null || nvm use default
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
  eval "$("$HOME/.nodenv/bin/nodenv" init -)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
  eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
fi

# Set up the ndenv of anyenv if preset
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
  export PATH=${HOME}/.anyenv/bin:${PATH}
  if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
    eval "$(anyenv init -)"
  fi
fi

# Set up asdf-vm if present
if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
  # shellcheck source=/dev/null
  . "$HOME/.asdf/asdf.sh"
elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
  # shellcheck source=/dev/null
  . "$(brew --prefix asdf)/asdf.sh"
fi

# Set up volta if present
if [[ -x "$HOME/.volta/bin/node" ]]; then
  export VOLTA_HOME="$HOME/.volta"
  export PATH="$VOLTA_HOME/bin:$PATH"
fi

# Set up the fnm node version manager if present
if [[ -x "$HOME/.fnm/fnm" ]]; then
  eval "$("$HOME/.fnm/fnm" env)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix fnm)/bin/fnm" ]]; then
  eval "$("$(brew --prefix fnm)/bin/fnm" env)"
fi

EDIT 2:

Still stuck, I tried the following steps but no luck:

  1. completely removed brew installed node and then installed nvm, now when I do, which node, which npm, which yarn, I get the following output paths:
/Users/username/.nvm/versions/node/v16.13.2/bin/node
/Users/username/.nvm/versions/node/v16.13.2/bin/yarn
/Users/username/.nvm/versions/node/v16.13.2/bin/npm
  1. then I removed my project’s Xcode derived data, project’s node modules, pods and re-installed everything hoping the new nvm node would download packages with the correct node version, but nope the SAME EXACT error saying:
/bin/sh -c /Users/username/Library/Developer/Xcode/DerivedData/myapp-bqzfnxmekpsgkmfaztyrfllaudqg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00047A70.sh
Node found at: /opt/homebrew/Cellar/node/19.0.1/bin/node
/Users/username/Desktop/algoguru/algoguru/ios/Pods/../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/react_native_pods_utils/script_phases.sh: line 83: /opt/homebrew/Cellar/node/19.0.1/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

I don’t understand this Node found at: /opt/homebrew/Cellar/node/19.0.1/bin/node, I already removed every brew installed node and then also tried to navigate to the same path but none could be found, but here in error it says otherwise…

Can someone help here? Really stuck! No matter what I do, I cannot seem to get rid of this error.

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve it, there was a hidden file xcode.env.local inside my project's ios folder, inside it, it had the following path: export NODE_BINARY="/opt/homebrew/Cellar/node/19.0.1/bin/node", so changing this to my current node path (using which node), it started working.


  2. I have the same error on my machine and looks like it is related to nvm. I fixed it by patching React Native. Here my patch.

    diff --git a/node_modules/react-native/scripts/find-node.sh b/node_modules/react-native/scripts/find-node.sh
    index 5d6d2c4..ceabb9e 100755
    --- a/node_modules/react-native/scripts/find-node.sh
    +++ b/node_modules/react-native/scripts/find-node.sh
    @@ -4,7 +4,7 @@
     # This source code is licensed under the MIT license found in the
     # LICENSE file in the root directory of this source tree.
     
    -set -e
    +set +e
     
     # remove global prefix if it's already set
     # the running shell process will choose a node binary and a global package directory breaks version managers
    
    

    you can use https://github.com/ds300/patch-package to apply it or just change it mannualy.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search