react-native: Weird build failure on Xcode after updating to RN 0.66.1

Description

After updating RN from 0.65.1 to 0.66.1, my iOS builds were failing with the following errors.

Screenshot 2021-10-18 at 17 15 49

I thought one of the libraries I’m using is not compatible with the new version, so I’ve started a new project from the typescript template and added them one by one. I turned out that that every time I add a new library with a native change, I get this error message and the only way to bypass it is by cleaning the project and restarting it with the following commands.

rm -rf node_modules ios/build ios/Pods ios/Podfile.lock && yarn cache clean yarn && cd ios && pod install && cd ../ yarn start --reset-cache

React Native version:

System:
    OS: macOS 11.6
    CPU: (8) arm64 Apple M1
    Memory: 353.69 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.9.1 - /opt/homebrew/bin/node
    Yarn: 1.22.11 - /opt/homebrew/bin/yarn
    npm: 7.21.1 - /opt/homebrew/bin/npm
    Watchman: 2021.09.13.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 29, 30, 31
      Build Tools: 29.0.2, 30.0.2, 31.0.0
      System Images: android-31 | ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 13.0/13A233 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.1 => 0.66.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Init a new project (I tested only on Typescript)
  2. Install dependencies, build from Xcode
  3. Install a library any native change so that you can pod install after too (I guarantee it works with the following: react-native-svg + react-native-svg-transformer, react-native-reanimated, react-native-device-info, react-native-dotenv, react-native-file-logger, react-native-safe-area-context)
  4. Restart metro and rebuild from Xcode

Expected Results

App should build successfully as it normally does.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 20
  • Comments: 37 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@J6ey @askndaer1 Hello, i want to share this even though i am in total disbelief that i could get it working because of this.

I had to make sure to place the project (so when i type npx react-native init AppName) in a folder route that must not include any spaces.

This will cause errors ~ cd Desktop/this\ wont\ work && npx react-native init AppName This will work flawlessly ~ cd Desktop/this-will/ && npx react-native init AppName

Some info about my config:

  • I have installed pod (v 1.11.2) through sudo gem install cocoapods and i also had to install ffi, with the same command, since it is recommended for mac M1 users.
  • Latest node version, through homebrew brew install node
  • Xcode 13.1

Please let me know if your issues can be solved by checking this painfully simple thing.

@Deepacks I had the same issue on “react-native”: “0.66.1” Changing back to “react-native”: “0.65.1” in the package.json, then npm install, pod update, pod install fixed it for me!

Also be sure to comment out __apply_Xcode_12_5_M1_post_install_workaround(installer)

Finaly found the issue! I traced it down to a difference in how cp command from GNU Coreutils and the BSD one in MacOS works. The cp -R command is used in the last phase of the script that script_phase.sh, that copies the files from a temporary directory (out/) to the final destination launched this command:

cp -R "build/generated/ios/out/" "build/generated/ios"

GNU Coreutils cp interpret this as copy the directory build/generated/ios/out/ to build/generated/ios/out, which are the same file, and thus the command fails, while BSD interpret this as copy build/generated/ios/out/* to build/generated/ios/ (by the way, it’s not clear to me what behavior is POSIX compliant, it seem to me the second one).

By removing the GNU Coreutils from the PATH it works as expected (I did have them in PATH since I mainly use Linux and I’m used to them). A mystery solved.

@Joshuapwilley - https://github.com/facebook/react-native/pull/35382 has this merged.

    # Copy all output to output_dir
-   cp -R "$TEMP_OUTPUT_DIR/" "$RCT_SCRIPT_OUTPUT_DIR" || exit 1
+   cp -R "$TEMP_OUTPUT_DIR/." "$RCT_SCRIPT_OUTPUT_DIR" || exit 1

This one byte commit (the “/.” wasn’t needed on the destination directory above) fixes the issues for our team (which is using the GNU coreutils version of the cp command).

Thanks for doing the hard work of finding this sucker.

Finaly found the issue! I traced it down to a difference in how cp command from GNU Coreutils and the BSD one in MacOS works. The cp -R command is used in the last phase of the script that script_phase.sh, that copies the files from a temporary directory (out/) to the final destination launched this command:

cp -R "build/generated/ios/out/" "build/generated/ios"

GNU Coreutils cp interpret this as copy the directory build/generated/ios/out/ to build/generated/ios/out, which are the same file, and thus the command fails, while BSD interpret this as copy build/generated/ios/out/* to build/generated/ios/ (by the way, it’s not clear to me what behavior is POSIX compliant, it seem to me the second one).

By removing the GNU Coreutils from the PATH it works as expected (I did have them in PATH since I mainly use Linux and I’m used to them). A mystery solved.

For anyone else experiencing this issue, another solution is to use patch-package to patch this file: node_modules/react-native/scripts/react_native_pods_utils/script_phases.sh

Change this line: cp -R "$TEMP_OUTPUT_DIR/" "$RCT_SCRIPT_OUTPUT_DIR" || exit 1

To this: cp -R "$TEMP_OUTPUT_DIR/." "$RCT_SCRIPT_OUTPUT_DIR/." || exit 1

This change should make this work with GNU and BSD.

@lunaleaps I don’t think this issue should be closed and I’m not sure if this is an upgrade issue.

HI @facebook, Thank you for wasting 6hr of my day.

@J6ey @askndaer1 Hello, i want to share this even though i am in total disbelief that i could get it working because of this.

I had to make sure to place the project (so when i type npx react-native init AppName) in a folder route that must not include any spaces.

This will cause errors ~ cd Desktop/this\ wont\ work && npx react-native init AppName This will work flawlessly ~ cd Desktop/this-will/ && npx react-native init AppName

Some info about my config:

  • I have installed pod (v 1.11.2) through sudo gem install cocoapods and i also had to install ffi, with the same command, since it is recommended for mac M1 users.
  • Latest node version, through homebrew brew install node
  • Xcode 13.1

Please let me know if your issues can be solved by checking this painfully simple thing.

The above worked.

Is it my imagination or since React Native version 0.64.2 getting a simple app going without any issues right out of the gate has been practically impossible. Add react-native-reanimated version 2 to the mix and I spend hours getting a basic app going.

I just come across this error and cleaning build folder in Xcode worked for me, but I’m not sure if this works all the time

@Joshuapwilley anything preventing the change you are suggesting to be submitted as a PR? Is there one out already?

Upgrading to the latest RN version fixed it.

It’s also a problem with a new react-native project …, not just an upgrade.