React Native

How to Resolve "React Native iOS Build Failure: Command PhaseScriptExecution Failed"

4 min read by DebuggedIt

Quick answer

An iOS build fails in Xcode (or via the command line) pointing at a failed "PhaseScriptExecution" step, which is Xcode's generic label for any custom build...

An iOS build fails in Xcode (or via the command line) pointing at a failed "PhaseScriptExecution" step, which is Xcode's generic label for any custom build script — most commonly the one that bundles your JavaScript into the app. Like similar generic build-tool errors, the real cause is a specific script failure hidden in a more detailed log.

The Problem

The build fails with a message naming the failed phase but not the actual error:

Command PhaseScriptExecution failed with a nonzero exit code

** BUILD FAILED **

The following build commands failed:
	PhaseScriptExecution [CP-User]\ [RN]Bundle\ React\ Native\ code\ and\ images /path/to/build.sh
(1 failure)

Running the equivalent command-line build shows a similarly brief summary unless you dig into the full log:

$ npx react-native run-ios
error Command PhaseScriptExecution failed with a nonzero exit code.
Info.plist: Building the info plist file requires an application target

Why It Happens

The named script (typically the "Bundle React Native code and images" build phase) runs Metro's bundling process as part of the native iOS build, and a nonzero exit code from that script means something inside the JavaScript bundling step itself failed. Xcode faithfully reports that the script failed, but doesn't surface the script's own detailed output in the top-level summary. Common underlying causes:

  • A JavaScript syntax or import error that Metro can't bundle, essentially the same category of failure as a Metro Bundler error, just triggered through Xcode's build process instead of a standalone npx react-native start.
  • Node isn't found in the environment Xcode's build script runs under — Xcode's build phases execute with a different, more limited environment than your interactive terminal shell, and if Node was installed via nvm or a similar version manager, Xcode's script may not be able to locate it at all.
  • An outdated or corrupted node_modules, especially after switching branches without reinstalling dependencies.
  • A misconfigured Info.plist or missing build setting, as hinted at in the second example above, unrelated to JavaScript bundling but still surfacing through the same generic phase-execution failure message.

The Fix

Get the actual script output rather than relying on Xcode's summary. In Xcode itself, click on the failed build step in the Report Navigator to expand its full log — this is where the real underlying error actually lives. From the command line, build with verbose output instead:

npx react-native run-ios --verbose

If the underlying error is a Node-not-found issue (common with nvm-managed Node installations), check what Node version and path your shell resolves versus what Xcode's build script environment can see:

which node
/Users/you/.nvm/versions/node/v20.11.0/bin/node

Xcode's build phase script often runs with a minimal PATH that doesn't include nvm's shims. Update the "Bundle React Native code and images" script phase in Xcode to explicitly source your Node version manager before running the bundling step:

# In the Xcode build phase script (Build Phases tab)
export NODE_BINARY=$(command -v node)
../node_modules/react-native/scripts/react-native-xcode.sh

If the real error turns out to be a JavaScript bundling failure (a syntax error, a broken import), fix it the same way you would any Metro bundling error — try running Metro directly outside of Xcode first, since it often gives a clearer, less nested error message:

npx react-native start --reset-cache

Reproduce the error there, fix the underlying JavaScript issue, then retry the iOS build.

For a stale node_modules or Pods state, clean both and reinstall from scratch:

rm -rf node_modules
npm install
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
npx react-native run-ios

Still Not Working?

If the expanded Xcode log still doesn't clarify the actual failure, run the bundling script manually and directly, exactly as Xcode would invoke it, which often surfaces the underlying error far more clearly than reading it through Xcode's build log UI:

cd ios
export NODE_BINARY=$(command -v node)
../node_modules/react-native/scripts/react-native-xcode.sh

Running it this way in your own terminal gives you the script's raw output directly, without any of Xcode's log truncation or nested formatting, which is often the fastest path to finally seeing the actual root-cause error message rather than continuing to interpret an indirect summary.