react-native: After upgrading to react-native 0.59 iOS build fails

🐛 Bug Report

After updating to react-native 0.59 and trying to build the app for iOS I get the following error:

Build input file cannot be found: ‘/app/node_modules/react-native/ReactCommon/yoga/yoga/YGFloatOptional.cpp’

What’s strange to me is, that I can’t find this file here either in the current master: react-native/tree/master/ReactCommon/yoga/yoga (only YGFloatOptional.h)

To Reproduce

We upgraded a mid sized project from 0.57.7 → 0.59.

Expected Behavior

Build should run through just fine like it did before.

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
      Memory: 2.95 GB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.1 - /var/folders/1r/ymkpxdlj21lb638kzp4jxvwm0000gn/T/yarn--1552463658468-0.20119758467048565/node
      Yarn: 1.13.0 - /var/folders/1r/ymkpxdlj21lb638kzp4jxvwm0000gn/T/yarn--1552463658468-0.20119758467048565/yarn
      npm: 6.4.1 - /usr/local/Cellar/node@10/10.15.1/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 25, 27, 28
        Build Tools: 23.0.1, 23.0.3, 24.0.1, 25.0.0, 27.0.3, 28.0.3
        System Images: android-24 | ARM 64 v8a, android-24 | ARM EABI v7a, android-24 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.0 => 0.59.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 105
  • Comments: 69 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I got the same issue…, Every time there is some issue with upgrades in react native so tired…

@jvandenaardweg I think you’re right that it’s a caching issue.

For me what worked was deleting my Xcode’s derived data folder and restarting Xcode. rm -rf ~/Library/Developer/Xcode/DerivedData

Once I restarted, I attempted a build and it failed and prompted me to close and reopen my xcode workspace. Once I did that, I tried to build again and it worked.

Add these lines to your Podfile:

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

and run

pod install

none of them worked

I have just reproduced this issue with XCode: 10.1 and RN 0.59.0.

EDIT 1: I could reproduce with XCode UI build tool ; but it’s working fine with react-native run-ios (make sure to have the latest 2.x cli).
EDIT 2: I managed to make it work with XCode 10.1 by enabling legacy build. Related to #19573

Every time I encounter a hair-pulling issue with RN giving me some nonsense error message, I go on a desperate github hunt for solutions. Most of the time the solution is delete cache, delete derived data, reopen Xcode, clear build folders etc. Over the years I’ve put together this bash script that I’ve added as an npm script in my package.json. Now my first goto solution for most issues is npm run clear.

// package.json
{
  "scripts": {
    "clear": ". scripts/Clear.sh",
  }
}
// scripts/Clear.sh
#!/bin/bash

echo "rm -rf ios/build..."
rm -rf ios/build

echo "rm -rf android/app/build..."
rm -rf android/app/build

echo "Removed all Xcode derived data..."
rm -rf ~/Library/Developer/Xcode/DerivedData

echo "rm -rf lib... (for Flow)"
rm -rf lib

echo "watchman watch-del-all..."
watchman watch-del-all

echo "rm -rf node_modules..."
rm -rf node_modules

echo "npm install..."
npm install

echo "rm -rf $TMPDIR/react-*..."
rm -rf $TMPDIR/react-*

echo "rm -rf $TMPDIR/haste-map-react-native-packager-*..."
rm -rf $TMPDIR/haste-map-react-native-packager-*

PS. And it solved this problem for me too 😄

After using npm audit fix, my ‘react-native’ are upgraded automatically to version 0.59 and I can’t not build my project. Solution: Downgrade version to lower one. npm install react-native@<version> example : npm install react-native@0.57.8

Thanks @jpudysz . Following your solution, I then get the following error: ‘folly/Portability.h’ file not found in JSBundleType.h

Does anyone know what’s going on?

Many thanks.

downgrade to "react-native": "0.57.4", than it works again

needing to guess

We know that upgrading has been a long lasting pain for the community so starting v0.59 we have introduced a new flow via the new CLI.

That said we have been writing the breaking changes in the changelog and in the releases tab so there is no real guessing needed.

Anyway, closing since this is clearly related to upgrading - also, in general you can use rn-diff-repo to check for all the necessary steps when upgrading.

I had the exact same issue. The good old rm -rf node_modules && npm i and cleaning the build folders did it for me

I was also seeing the #include <folly/Portability.h> error. The issue in my case were missing subspecs in the podfile.

It builds fine for me with:

  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge', # Include this for RN >= 0.47
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # needed for debugging
    'RCTImage',
    'RCTWebSocket', # Needed for debugging
    'RCTAnimation', # Needed for FlatList and animations running on native UI thread
    # Add any other subspecs you want to use in your project
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party deps podspec link
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

in my case, Xcode just did an automatic update and produced such problem. what i did to solve the problem was: cd ios rm -fr Pods rm Podfile.lock pod install

reinstall the Pods and Podfile solved my problem

So after following the upgrade diff to 59.4 (using rn-diff-purge), I still had the same issues as everyone here (YGFloatOptional.cpp error first, and then the folly/Portability.h error). However, none of the solutions worked by itself, so this is what I did to resolve the issues:

# Clean caches/build folder/existing pods
rm -rf node_modules
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ios/build
rm -rf ios/Pods

# Reinstall deps
npm install

Then updated my Podfile to the following:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'CityChallenge' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  pod 'React', :path => '../node_modules/react-native', subspecs: [
    # Comment out any unneeded subspecs to reduce bundle size.
    'Core',
    'CxxBridge', # --> I was missing Cxxbridge here, may have resolved the issue for me as well
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTCameraRoll',
    'RCTGeolocation',
    'RCTImage',
    'RCTNetwork',
    'RCTPushNotification',
    'RCTSettings',
    'RCTTest',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'RCTLinkingIOS'
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party --> This bit is also new
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'


end

After that I reinstalled the pods

cd ios
pod install

Only then the project started building successfully again

I gave up, I deleted all links to node_modules from Pods file then delete node_modules and build directory and re-installed anything then finally built successfully again.

This is so exhausting.

@jpudysz Yeah that worked after migrating to cocoapod and opening the XCode project with the .xcworkspace file. I had to react-native unlink and react-native link bridged libraries so that they use the Podfile instead.

Should legacy (no-cocoapod) linking be deprecated ?

please. downgraded Xcode 10.1

Alright folks, I think this issue is generally about build cache issues from upgrading (from reading the posts ) - so if you have issues, I think it can generally be fixed by:

  • Cleaning Derived data in Xcode
  • rm -rf node_modules; rm -rf Pods then re-install
  • Using react-native upgrade x.y.z

This is pretty much the same for every version, I bet. I would maybe look into making an issue on the react-native-cli about improving this and maybe running some of the commands itself.

The file seems to be deleted from the yoga project since 13 Dec 2018 and “inlined” into yoga/YGFloatOptional.h: https://github.com/facebook/yoga/commit/96d93f29826257ff6e9bb6c19211adb423029c29

My guess is the reference to ReactCommon/yoga/yoga/YGFloatOptional.cpp is not needed anymore.

Removing the cache and rebuilding the project didn’t work for me right away.

So I tried upgrading to React Native 0.59.1 then rebuilding the project. Also didn’t work.

However, THEN cleaning my node_modules, cache and build folders and rebuilding the project, did work, using:

rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && watchman watch-del-all && npm cache clean --force && npm cache verify && rm -rf ios/build && rm -rf node_modules/ && npm i

So, it seems cache related.

Upgrading to React Native 0.59.1 is maybe not needed, I think a part of the script did the trick for me.

Hope this helps others!

Run this command: $ conda deactivate

After trying what feels like pretty much everything, RN standard upgrade, git upgrade tool, applying diff patch I ended up recreating a completely new project and doing the extremely tedious work of rebuilding the code base. They say it’ll be better from 0.59 on… hopefully they’re right about that

Above solutions did not work, the following helped my project to build again.

cd ios
pod repo update
pod update

After running these commands, I was able to build on xcode but not using react-native run-ios. I then ran these commands (thanks https://github.com/facebook/react-native/issues/23886#issuecomment-509528212):

rm -rf ios/build
rm -rf ~/Library/Developer/Xcode/DerivedData
watchman watch-del-all
rm -rf node_modules
npm install

which helped me build using react-native run-ios again.

Hmm, I have just upgraded from 0.58.4 to 0.59, cleaned build directories in XCode and I was able to run both debug and archive the app. I am using XCode 10.1. My upgrade strategy:

  1. Bump dependencies according to most recent stable version.
  2. Walk through each compare in https://github.com/react-native-community/rn-diff-purge and apply it manually.

Wondering if everything might work for me because I had working 0.58.4 and just applied new stuff on top of it?

EDIT: I have also ran npm ci in order to remove my node_modules (just to make sure) and I was still able to build the app from XCode 🤔

EDIT2: And I don’t have YGFloatOptional.cpp:
Screen Shot 2019-03-13 at 12 55 51

In my case i just forgot to did the step:

if you are an iOS developer, you’ll need to manually link JavaScriptCore.framework when upgrading; this can be done via Xcode, and following the steps shown here.

example

after i did that, xcode just compile ok

React Native is unsustainable, 100 resolutions offered for every bug someone encounters. One change and the entire build process, boilerplate and reason to use react native falls apart. How can companies truly add this development process to a product pipeline. ridiculous!!!

I upgraded too but with no luck so far.

None of the above worked for me

“Between react-native 0.57.8 and 0.58.5 there is one big change that was added in the Xcode project is that you have to add JavaScriptCore.Framework to the Linked FrameWorks and Libraries” - from here

PLUS

@jvandenaardweg answer:

rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && watchman watch-del-all && npm cache clean --force && npm cache verify && rm -rf ios/build && rm -rf node_modules/ && npm i

Did the work for me.

It’s really frustrating as other have said, needing to guess what its breaking a code that was working before.

Also on Android I had to upgrade Build Gradle version to work again.

I’m getting the same issue upgrading from 0.57.8 -> 0.59.1. Looking at a fresh 0.59.1 init there is no YGFloatOptional.cpp file.

Delete derived data cd ios remove Pods and Podfile.lock pod install

They say it’ll be better from 0.59 on… hopefully they’re right about that

@philipaarseth I hope you ate your words when 0.60 came out 😆

rm -rf ~Library/Developer/XCode/DerivedData

the right line will be: rm -rf ~/Library/Developer/Xcode/DerivedData

Resolved with the following :

rm -rf node_modules
rm -rf ios/Pods
rm ios/Podfile.lock 
rm -rf ~Library/Developer/Xcode/DerivedData

Then I reinstalled my dependencies (npm & pod) and it worked 😃

I realize that my post was very unclear… Sorry about that. Here is the diff file that should make it more explicit for people having issue with ‘folly/Portability.h’

Try making the following modification to nodes_modules/react-native/React.podspec file, at least in my case it has worked ! I can now compile my project and launch it without problems.

diff --git a/node_modules/react-native/React.podspec b/node_modules/react-native/React.podspec

s.subspec "Core" do |ss|
[...]
     ss.header_dir           = "React"
     ss.framework            = "JavaScriptCore"
     ss.libraries            = "stdc++"
-    ss.pod_target_xcconfig  = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
+    ss.pod_target_xcconfig  = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"  \"$(PODS_ROOT)/Folly\"" }
   end

@jvandenaardweg I think you’re right that it’s a caching issue.

For me what worked was deleting my Xcode’s derived data folder and restarting Xcode. rm -rf ~/Library/Developer/Xcode/DerivedData

Once I restarted, I attempted a build and it failed and prompted me to close and reopen my xcode workspace. Once I did that, I tried to build again and it worked.

Thanks, I did that and it worked again.

After using @jpudysz, @jvandenaardweg and @johnryan tips, it build for me also. Thanks guys!

Hello,

After lots of digging, I’ve managed to get why I got the issue. Cleaning the cache and everything didn’t fix the problem for me and I was still having the #include <folly/Portability.h>.

It was compiling fine for the React project under my project, but failing to compile for the Pods I have.

Even after adding the Folly/glog/DoubleConversion pods, I was still having the problem.

I then amended the React.podspecs file to edit the Core subspec

After adding the Folly reference to the pod_target_xcconfig, it was compiling without any other issues.

ss.pod_target_xcconfig  = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"  \"$(PODS_ROOT)/Folly\"" }

And here is the full podfile I have

ENV['COCOAPODS_DISABLE_STATS'] = 'true'

target 'CryptoReact' do
  platform :ios, '9.0'

  pod 'CodePush', :path => '../node_modules/react-native-code-push'
  pod 'Firebase/Core', '~> 5.14.0'

  
  pod 'react-native-sqlite-storage', :path => '../node_modules/react-native-sqlite-storage'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga/yoga.podspec'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'react-native-randombytes', :path => '../node_modules/react-native-randombytes'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
  pod 'RNLocalize', :path => '../node_modules/react-native-localize/ios'
  pod 'react-native-camera', :path => '../node_modules/react-native-camera'
  pod 'RNPermissions', :path => '../node_modules/react-native-permissions'
  pod 'react-native-keep-awake', :path => '../node_modules/react-native-keep-awake'
  pod 'SwiftyJSON', '4.2.0'
  pod 'Charts', '3.1.1' 
  pod 'Fabric', '~> 1.9.0'
  pod 'Crashlytics', '~> 3.12.0'
  pod 'Firebase/Performance', '~> 5.14.0'
  pod 'Firebase/Auth', '~> 5.14.0'
  pod 'lottie-ios', :path => '../node_modules/lottie-ios'
  pod 'lottie-react-native', :path => '../node_modules/lottie-react-native'
  pod 'react-native-webview', :path => '../node_modules/react-native-webview'
  pod 'RNScreens', :path => '../node_modules/react-native-screens'
  pod 'ReactNativeExceptionHandler', :podspec => '../node_modules/react-native-exception-handler/ReactNativeExceptionHandler.podspec'
  pod 'RCTRestart', :path => '../node_modules/react-native-restart/ios'
  pod 'react-native-version-number', :path => '../node_modules/react-native-version-number'
  pod 'RNBackgroundFetch', :path => '../node_modules/react-native-background-fetch'

  pod 'React', :path => '../node_modules/react-native', :subspec => [
    'Core',
    'ART',
    'cxxreact',
    'CxxBridge', # Include this for RN >= 0.47
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # needed for debugging
    'RCTImage',
    'RCTWebSocket', # Needed for debugging
    'RCTAnimation', # Needed for FlatList and animations running on native UI thread
    'RCTPushNotification',
    # Add any other subspecs you want to use in your project
  ]
end

swift4 = ['Charts']

post_install do |installer|
installer.pods_project.targets.each do |target|
  target.build_configurations.each do |config|
    if swift4.include?(target.name)
      config.build_settings['SWIFT_VERSION'] = '4.1'
    end
  end
end
end