I'm trying to integrate React Native into an existing Swift iOS application using this integration guide: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html. The version of React Native is 0.53.0.
I have successfully installed all the required pods and now trying to build the project, but always getting the following compile error:
The error log:
While building module 'yoga' imported from ...node_modules/react-native/React/Base/RCTConvert.h:19:
In file included from <module-includes>:1:
In file included from ...ios/Vandebron/Pods/Target Support Files/yoga/yoga-umbrella.h:15:
In file included from ...node_modules/react-native/ReactCommon/yoga/yoga/YGNode.h:13:
...node_modules/react-native/ReactCommon/yoga/yoga/Yoga-internal.h:11:10: fatal error: 'algorithm' file not found
#include <algorithm>
^~~~~~~~~~~
1 error generated.
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.m:10:
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.h:10:
In file included from ...node_modules/react-native/React/Views/RCTViewManager.h:13:
...node_modules/react-native/React/Base/RCTConvert.h:19:9: fatal error: could not build module 'yoga'
#import <yoga/Yoga.h
This is a cocoapods problem. Try to expose only needed headers by edit the yoga.podspec file:node_modules/react-native/ReactCommon/yoga/yoga.podspec add this line at the end of yoga.podspec:
spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h',
Look like this:
source_files = 'yoga/**/*.{cpp,h}'
source_files = File.join('ReactCommon/yoga', source_files) if ENV['INSTALL_YOGA_WITHOUT_PATH_OPTION']
spec.source_files = source_files spec.source_files = source_files
+
+ # Only expose the needed headers
+ spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h', 'yoga/YGMacros.h'
+
end
Ref: https://github.com/facebook/react-native/issues/17893
The actual pull request: https://github.com/facebook/react-native/pull/17764 . Look at the comment by Plo4ox
.