React native error - react-native-xcode.sh: line 45: react-native: command not found Command /bin/sh failed with exit code 127
Solution 1
To solve this problem use following steps :
- Use node version v4.2.1
- cd into [your app]/node_modules/react-native/packager
- $sh ./packager.sh (for some reason this runs fine)
- Go into XCode and go to the Build Phases tab. Remove the last item on the list (the one that runs the script). So you're left with Target Dependencies, Compile Sources, Link Binary With Libraries, and Copy Bundle Resources.
Now hit build in XCode. Since the shell script is no longer part of the XCode build routine, it shouldn't fail. And if you have the react native client server running in another terminal window, then everything should run fine.
Solution 2
If you are using RN 0.46 or above:
There is a breaking change made by Facebook: the location of the script has been changed, more detail here
I was able to solve this error by:
- Opening the project in XCode
- Navigate to
Build Phases > Bundle React Native code and images
- Change
export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.sh
toexport NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh
Notice how packager
is now scripts
, which is where that file actually lives in latest version of RN
Solution 3
Simply change
../node_modules/react-native/packager/react-native-xcode.sh
to
../node_modules/react-native/scripts/react-native-xcode.sh
at
Xcode -> Select your Project -> "Build Phases" tab -> "Bundle React Native code and images"
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I get this error when trying to build any (new or old) project. My node is on version 4.2.1 and react-native is on version 0.1.7. I've looked at other people with the same problem so I've updated react-native to the latest version however I still cannot build any project through xcode.
-
Damien Sawyer over 8 yearsHi, could please explain in more detail what the "Build Phases tab" is? Cheers.
-
Pikachu-go over 8 yearsThere are 7 options in center section of Xcode -> General, Capabilities, Resource Tags, Info, Build Settings, Build Phases and Build Rules. Choose Build phases and proceed :)
-
typologist over 8 yearsI can confirm that this works. Just make sure you run the packager.sh every time you work.
-
Manjeet Singh almost 7 yearsthere is no packager in my react-native folder
-
Pikachu-go almost 7 years@ManjeetSingh skip that step and continue
-
Manjeet Singh almost 7 years@Pikachu-go I see in RN0.46 those things are moved to scripts folder
-
Manjeet Singh almost 7 years@Pikachu-go I see in RN0.46 those things are moved to scripts folder
-
Freewalker almost 7 yearsThis fixed it for us, thanks! For those trying to find this via web search, my exact error message was: Script-00DD1BFF1BD5951E006B06BC.sh: line 3: ../node_modules/react-native/packager/react-native-xcode.sh: No such file or directory ** BUILD FAILED **
-
Rodrigo Xavier over 6 yearsThis fixed for me. Should be choose as the best answer.
-
Şafak Çıplak almost 4 yearsYou saved my time. i didn't fix a couple days