18

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?

0

6 Answers 6

23

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

Sign up to request clarification or add additional context in comments.

10 Comments

I had a comment in my .env file (# with three words) and when I removed it, I got past this error 🤷‍♂️
where is this .env file located?
At the root of your project.
there is no env file in my project. :/
For some reason, I switched a comment from # the comment to ; the comment some time ago but switching it back to a # fixed it!
|
7

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

1 Comment

This solution did not work for me. :-/
5

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)

1 Comment

I didn't have this code in my Podfile but following these instructions which you have linked to fixed the issue: github.com/luggit/…
3

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

1 Comment

this helped me thx. i did rbenv install
0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.