Xcode Build Fails With Error Code 65 Due To .xcode.env.local Forcing Node 18 On React Native 0.76.9 With Node 20
Introduction
As a React Native developer, you may have encountered the frustrating issue of Xcode build failures with error code 65. This error is often caused by the .xcode.env.local
file, which forces Xcode to use a specific Node version. In this article, we will explore the root cause of this issue and provide two possible solutions to resolve it.
Description
The issue arises when you are using a React Native version lower than 0.78, such as 0.76.9, and have recently migrated from Node 18 to Node 20. The .xcode.env.local
file is automatically regenerated after cleaning the project and running pod install --repo-update
. This file forces Xcode to use a local Node version, which in this case is Node 18.
When you launch the app, you encounter the following error:
error export CLANG_WARN_DOCUMENTATION_COMMENTS=YES
error export CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER=NO
error export GCC_WARN_UNDECLARED_SELECTOR=YES
error export VALIDATE_PRODUCT=NO
error Failed to build ios project. "xcodebuild" exited with error code '65'.
Solution 1: Delete .xcode.env.local after each pod install
If you want to keep using Node 20 with a React Native version lower than 0.78, you can add a post-install script in your Podfile
to automatically delete .xcode.env.local
after each pod install
. This will prevent the file from being regenerated and forcing Xcode to use the wrong Node version.
To do this, add the following code to your Podfile
:
post_install do |installer|
File.delete('ios/.xcode.env.local')
end
After adding this code, run pod install --repo-update
and then launch your app as usual. It should work fine.
Solution 2: Upgrade to React Native 0.78 or above
The better long-term solution is to upgrade to React Native 0.78 or above. This version has much better support for Node 20, including fixes in scripts and internal dependencies like Hermes and node-gyp.
Upgrading to a newer version of React Native will ensure that you have the latest features and bug fixes, and will prevent issues like this from arising in the future.
Steps to Reproduce
To reproduce this issue, follow these steps:
- Use React Native 0.76.9 with Node 20 (recently upgraded from Node 18).
- Run
pod install --repo-update
in theios
folder. - Open the project in Xcode or run
react-native run-ios
. - Observe the build fails with error code 65 and logs mentioning
.xcode.env.local
forcing Node 18.
React Native Version
0.76.9
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
react native 0.76.0
node 20
Stacktrace or Logs
`error export CLANG_WARN_DOCUMENTATION_COMMENTS=YES
error export CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER=NO
error export GCC_WARN_UNDECLARED_SELECTOR=YES
error export VALIDATE_PRODUCT=NO
error Failed to build ios project. "xcodebuild" exited with error code '65'.
Mandatory Reproducer
https://github.com/facebook/react-native/issues/31259
Screenshots and Videos
No response
Q: What is the root cause of the Xcode build failure with error code 65?
A: The root cause of the Xcode build failure with error code 65 is the .xcode.env.local
file, which forces Xcode to use a specific Node version. In this case, the file is forcing Xcode to use Node 18, even though the project is using Node 20.
Q: Why is the .xcode.env.local file being regenerated?
A: The .xcode.env.local
file is being regenerated after cleaning the project and running pod install --repo-update
. This is because the file is automatically generated by Xcode to use a local Node version.
Q: How can I prevent the .xcode.env.local file from being regenerated?
A: You can prevent the .xcode.env.local
file from being regenerated by adding a post-install script in your Podfile
to delete the file after each pod install
. This will prevent the file from being regenerated and forcing Xcode to use the wrong Node version.
Q: What is the better long-term solution to this issue?
A: The better long-term solution is to upgrade to React Native 0.78 or above. This version has much better support for Node 20, including fixes in scripts and internal dependencies like Hermes and node-gyp.
Q: How do I upgrade to React Native 0.78 or above?
A: To upgrade to React Native 0.78 or above, you can run the following command in your terminal:
npx react-native upgrade
This will upgrade your project to the latest version of React Native.
Q: What are the benefits of upgrading to React Native 0.78 or above?
A: Upgrading to React Native 0.78 or above provides several benefits, including:
- Better support for Node 20
- Fixes in scripts and internal dependencies like Hermes and node-gyp
- Improved performance and stability
- New features and bug fixes
Q: How do I troubleshoot the Xcode build failure with error code 65?
A: To troubleshoot the Xcode build failure with error code 65, you can try the following steps:
- Check the
.xcode.env.local
file to see if it is being regenerated. - Run
pod install --repo-update
to ensure that the file is deleted. - Check the project's
Podfile
to see if there are any issues with the file. - Try upgrading to React Native 0.78 or above.
Q: What are some common issues that can cause the Xcode build failure with error code 65?
A: Some common issues that can cause the Xcode build failure with error code 65 include:
- Using a React Native version lower than 0.78 with Node 20
- Having issues with the
.xcode.env.local
file - Having issues with the project's
Podfile
- Having issues with the project's dependencies
By following these troubleshooting steps, you should be able to resolve the Xcode build failure with error code 65 and get your project up and running again.