facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.75k stars 24.29k forks source link

Command PhaseScriptExecution failed with a nonzero exit code - Error when Archive on Xcode 14.3 #36762

Open leofolive opened 1 year ago

leofolive commented 1 year ago

Description

Hi Guys, I'm trying to perform an archive using 0.71.5 but I'm getting an error.

The error occurs in Build phase "[CP] Embed Pods Frameworks", when he runs the script with:

"${PODS_ROOT}/Target Support Files/Pods-MyApp/Pods-MyApp-frameworks.sh"

React Native Version

0.71.5

Output of npx react-native info

System: OS: macOS 13.3 CPU: (8) arm64 Apple M1 Memory: 79.22 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm Watchman: 2022.11.14.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/leonardo.felipe/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: API Levels: 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0 System Images: android-32 | Google APIs ARM 64 v8a, android-33 | Google APIs ARM 64 v8a Android NDK: 22.1.7171670 IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 14.3/14E222b - /usr/bin/xcodebuild Languages: Java: 11.0.14.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.5 => 0.71.5 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Snack, code example, screenshot, or link to a repository

Investigating the problem I noticed that the problem occurs in the "Symlinked..." of the script Pods-MyApp-frameworks.sh

  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi

Workaround is to update all the generated ...-frameworks.sh files to add the -f flag to the call to readlink. In other words, replace source="$(readlink "${source}")" with source="$(readlink -f "${source}")"

The Workaround above was suggested for the issue below and has now been merged into the cocoapods repository. I believe we will need an RC with this FIX pointing to the new version of cocoapods as soon as it is released.

https://github.com/CocoaPods/CocoaPods/issues/11808 https://github.com/CocoaPods/CocoaPods/pull/11828

yihu5566 commented 1 year ago

@yihu5566 请问你的是m2 pro环境吗 ?我改了还是没解决问题

不是的

sokolbiba commented 1 year ago

Facing the same issue.

rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/97f6331a-ba75-11ed-a4bc-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9]

Command PhaseScriptExecution failed with a nonzero exit code

UPDATE adding '-f' on the highlighted line in this file resolved my issue. You can try this

Screenshot 2023-04-13 at 9 56 22 AM

This worked for me

abazudosen commented 1 year ago

still not wokring...any fix??

vishaltanna commented 1 year ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

Thanks for solution it's working for me.

abdelaziz123456 commented 1 year ago

still not working for me , is there any solution ?

bgrajesh57 commented 1 year ago

facing same issue Xcode version 14.3.1 (14E300c). assist me on this

Aminsh7 commented 1 year ago

after days of searching the net, only removing the script "Bundle React Native code and images.' in project,pbxproj did the trick. In my case, the 'files' array was empty, so it didn't do anything. just Remove:

/ Begin PBXShellScriptBuildPhase section / 00DD1BFF1BD5951E006B06BC / Bundle React Native code and images / = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Bundle React Native code and images"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; };

MiteshKalal7 commented 1 year ago

remove space from project folder name.

Aminsh7 commented 1 year ago

remove space from project folder name.

there is no space

mljlynch commented 1 year ago

This is happening to me due to:

env: node: No such file or directory

Would it be possible to get a more helpful error message?

fukemy commented 1 year ago

any solution? XCode 15 + RN 0.72.5 same problem

surajsharma commented 1 year ago

check if anyything is running on port 8081 and kill it, worked for me

leofolive commented 1 year ago

This is happening to me due to:

env: node: No such file or directory

Would it be possible to get a more helpful error message?

Try this: sudo ln -s "$(which node)" /usr/local/bin

ivanrndev commented 1 year ago

Try to check the ios/.xcode.env file.

Inside, there should be the line: export NODE_BINARY=$(command -v node)

Try replacing it with: export NODE_BINARY=your_node_path for example, it can be: export NODE_BINARY=/Users/myuser/.nvm/versions/node/v18.15.0/bin/node

cgtorniado commented 1 year ago

check if anyything is running on port 8081 and kill it, worked for me

This is worked for me thank you!

buscanopaul commented 1 year ago

I'm using react native 0.63 running mac Book Pro M2 and Xcode 14.3. I fixed this by going to Build settings > excluded architectures and deleting arm64.

or go to vscode ios > .xcodeproj > project.pbxproj

and then find and delete "EXCLUDED_ARCHS = arm64; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;

tdkhoasg commented 11 months ago

This also happened to me. Init project on M1, Xcode 14.3, React-Native 0.72.6 Check the path to where your project is located and make sure there aren't any folders with spaces in the name. Error: /Users/username/Documents/My Team/MyApp just update to: /Users/username/Documents/MyTeam/MyApp

soundaraj commented 11 months ago

Try this if your using NVM

sudo ln -s "$(which node)" /usr/local/bin/node

jimdog1001 commented 11 months ago

check for spaces as you are naming the project folders. Use space alternatives.

so simple yet saved me lol. project was in a folder that contained a space

oleksiizhuk commented 11 months ago

The solution that worked for me was to delete ".xcode.env.local" and start the whole process again

MattFixesFaults commented 11 months ago

Same issue with React Native 0.72.6 and xcode 15.0.1 and M1

luoxuhai commented 11 months ago

对我有用的解决方案是删除“.xcode.env.local”并再次启动整个过程

this works for me

anhtuank7c commented 11 months ago

Try to check the ios/.xcode.env file.

Inside, there should be the line: export NODE_BINARY=$(command -v node)

Try replacing it with: export NODE_BINARY=your_node_path for example, it can be: export NODE_BINARY=/Users/myuser/.nvm/versions/node/v18.15.0/bin/node

This exactly what I need to fix the issue on RN 0.72.6, xCode 15.01 and Mac M1

maartenvandillen commented 11 months ago

I had this problem after renaming the project folder.

zaraganja commented 11 months ago

remove space from project folder name.

Thank you , you saved my day

mljlynch commented 10 months ago

This is happening to me due to: env: node: No such file or directory Would it be possible to get a more helpful error message?

Try this: sudo ln -s "$(which node)" /usr/local/bin

Try that where? In the console or in xcode?

mljlynch commented 10 months ago

This fixed it for me. Locally I'm using NVM and our project uses sentry. The Sentry docs have some helpful suggestions this error:

https://docs.sentry.io/clients/react-native/manual-setup/#using-node-with-nvm-or-notion

Adding something like this to the Bundle React Native code and images step fixed the problem.

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

Note: In the case you are uploading symbols to sentry you will have to add it to that step as well.

recallwei commented 10 months ago

The solution that worked for me was to delete ".xcode.env.local" and start the whole process again

This worked for me.

iamtechieboy commented 10 months ago

Command PhaseScriptExecution failed with a nonzero exit code

i am getting still this issue after doing all solution above. I am using OneSignal and do you think guys is it because of this package.

thanks for replaying

rainboi commented 10 months ago

I had this issue after changing node version (either by nvm or brew).

This worked for me -

Updated ios/.xcode.env.local file contents to be

export NODE_BINARY=/usr/local/bin/node

got "/usr/local/bin/node" by "which node" in terminal

SamuelScheit commented 10 months ago

my issue was the node_modules/react-native/scripts/react-native-xcode.sh script, specifically the IP env variable. I've replaced the for loop and if check, with the fallback command:

# Enables iOS devices to get the IP address of the machine running Metro
if [[ ! "$SKIP_BUNDLING_METRO_IP" && "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  # for num in 0 1 2 3 4 5 6 7 8; do
  #   IP=$(ipconfig getifaddr en${num})
  #   if [ ! -z "$IP" ]; then
  #     break
  #   fi
  # done
  # if [ -z "$IP" ]; then
  IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\   -f2  | awk 'NR==1{print $1}')
  # fi
  echo "IP: $IP"

  echo "$IP" > "$DEST/ip.txt"
fi

I'm not sure what the cause of this error is, but maybe this helps someone else

outlandnish commented 10 months ago

my issue was the node_modules/react-native/scripts/react-native-xcode.sh script, specifically the IP env variable. I've replaced the for loop and if check, with the fallback command:

# Enables iOS devices to get the IP address of the machine running Metro
if [[ ! "$SKIP_BUNDLING_METRO_IP" && "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  # for num in 0 1 2 3 4 5 6 7 8; do
  #   IP=$(ipconfig getifaddr en${num})
  #   if [ ! -z "$IP" ]; then
  #     break
  #   fi
  # done
  # if [ -z "$IP" ]; then
  IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\   -f2  | awk 'NR==1{print $1}')
  # fi
  echo "IP: $IP"

  echo "$IP" > "$DEST/ip.txt"
fi

I'm not sure what the cause of this error is, but maybe this helps someone else

Seconding this - commenting this out fixes builds for physical devices. This issue doesn't appear when building for the Simulator

rahulkumar1409 commented 9 months ago

export NODE_BINARY=/Users/myuser/.nvm/versions/node/v18.15.0/bin/node

this issue is occurring due to change in node version. Solution for that is when you upgrade your node version just delete ".xcode.env.local" file and build again. I will work like piece of cake. thanks.

varungarg168 commented 9 months ago

my issue resolve when i give node_module write permission with all enclosed items

rdnsan commented 9 months ago

Try to check the ios/.xcode.env file.

Inside, there should be the line: export NODE_BINARY=$(command -v node)

Try replacing it with: export NODE_BINARY=your_node_path for example, it can be: export NODE_BINARY=/Users/myuser/.nvm/versions/node/v18.15.0/bin/node

It worked for me!

habvtng commented 9 months ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

it's worked for me, thanks very much

rdnsan commented 9 months ago

try this, it worked for me

# ios/.xcode.env
export NODE_BINARY=$(which node)
lucaswitch commented 9 months ago

For anyone still having this issue, it could be a miss on import statement on js code. Just run: yarn run ios(or similar) then the terminal must show the complete error stacktrace.

sonnv106 commented 9 months ago

Same issue with React Native "0.73.2" and xcode 14.0 and M1

kumarsaurav26198 commented 8 months ago

Hi,

I am also getting the same error.

like [Command PhaseScriptExecution failed with a nonzero exit code]

Screenshot at Jan 25 16-13-39

magnet@Magnets-MacBook-Pro Grocery % npx react-native info info Fetching system and libraries information... System: OS: macOS 14.3 CPU: (8) arm64 Apple M2 Memory: 104.13 MB / 8.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 18.16.0 path: /usr/local/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.6.6 path: /opt/homebrew/bin/npm Watchman: version: 2023.05.22.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.12.1 path: /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms:

WBohdan commented 8 months ago

I opened the logs in XCode and saw that my error falls in "Bundle React Native code and images" and in the recommendations it was written that two libraries should be install "Please install react-dom@18.2.0, @expo/metro-runtime@~3.1.1". I installed the libraries using the command "npx expo install react-dom @expo/metro-runtime" and that helped me.

Screenshot 2024-01-30 at 16 59 54 Screenshot 2024-01-30 at 17 01 24 Screenshot 2024-01-30 at 17 01 52
RaguRam1991 commented 8 months ago
set +e

this worked for me, thanks.

RaguRam1991 commented 8 months ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

it seems we need to change it everytime when installing/uninstalling a package.

leofolive commented 8 months ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

it seems we need to change it everytime when installing/uninstalling a package.

A patch can be generated using patch-package.

markrickert commented 8 months ago

I just encountered this upgrading a project from 0.73.3 to 0.73.4 with Xcode 15.2. The solution for me was to delete the ./ios/.xcode.env.local file. It was overriding the correct settings in ./ios/.xcode.env.

umartariq247 commented 8 months ago

where does ios/.xcode.env exist, i couldn't find that

ApoIesh commented 8 months ago

try removing the currently installed Node version and download a different version of Node you could use NVM to manage different versions of Node if you already use it try another version

i solve this error by downgrade my version

ardacmen commented 8 months ago

it is path issue. just check your ios folders path, if it has empty space please remove it and reindex all project

skjangid commented 7 months ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

God, you saved me!!!!!!!!

Thanks, this is worked for me :)

ashirkhan94 commented 7 months ago

Fixed this by updating updating node_modules/react-native/scripts/find-node.sh @ L7

- set -e
+ set +e

P.S. Tried switching node from nvm to brew but that didn't made any difference.

Worked for me thanks👍