PhaseScriptExecution failed for react-native-config on Xcode build

27.4k views Asked by At

I am trying to build my React Native project on Xcode and it is failing. The build target is react-native-config with the error: Run custom shell script '[CP-User] Config codegen' "Command PhaseScriptExecution failed with a nonzero exit code".

Trying to run it with --verbose, I get the following:

The following build commands failed: PhaseScriptExecution [CP-User]\ Config\ codegen /User/userName/Library/Developer/Xcode/DerivedData/projectName/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-config-build/Script-21BEEA33BD6A21BF27B73D38DC1AD4.sh

I am running React Native 0.63.1 with React-Native-Config 1.4.1 and I have tried reinstalling node_modules, pods, deleting DerivedData and cleaning the build but no luck. I also do not see any references to react-native-config under Build Phases > Run Script.

Any ideas how to solve this?

6

There are 6 answers

10
Karl Lopez On BEST ANSWER

Usually, this is caused by a badly formatted .env file. Double-check your .env.

1
M_Badrah On

I had the same Problem, I followed a tutorial to build ios, it is pretty old (one year) in tutorial I added code which include some thing like

post_install do |installer|
installer.pods_project.targets.each do |target|
  if target.name == 'React'
  target.remove_from_project
  end
  if target.name == 'react-native-config'
    phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
    phase.shell_script = 'cd ../../'\
    '&& RNC_ROOT=./node_modules/react-native-config/'\
    '&& export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig'\
    '&& export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig'\
    '&& ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby'
    target.build_phases << phase
    target.build_phases.move(phase,0)
  end
 end
end

please delete it from podfile and follow the doc of react-native-config to use environment variables here after delete dont forget pod install

while building take care of build scheme (which one are you using while build time)

0
Gulshan Prajapati On

Occur due to some mismatch of packages, search for a package which shows the error and remove the package

After that

delete ios folder install react native eject package

npm i react-native-eject

re-create ios folder

npx react-native eject

install pod

cd ios
pod install
1
Mohamad El-Mordaa On

Usually this problem when a dependency is not updated.

You can try the following steps:

1-) cd ios
2-) rm -rf Podfile.lock
3-) rm -rf Pods
4-) delete .xcworkspace
5-) pod install
0
Mahad Ahmed On

For me, I used ts-node to run some typescript code in the Run Script phase, the ts-node executable was not in /usr/local/bin/ts-node which caused the build to fail.

Try to run the code inside the Run Script editor directly in the terminal, that might give you a clue about why the build fails.

1
Shayan Ali Abbasi On

If anyone is facing this issue while using rbenv, please ensure that ruby is installed locally in project folder.