React native pod file use_modular_headers! throwing Redefinition of module 'ReactCommon' error
Description
Podfile doesn't support use_modular_headers! directive, get an error at build time
Steps to reproduce
create a sample react native project npx react-native init MyApp
add use_modular_headers! to the Podfile
do pod install
Getting error as Redefinition of module 'ReactCommon' error in Xcode project when building
React Native Version
0.74.2
Affected Platforms
Build - MacOS
Output of npx react-native info
System:
OS: macOS 14.4.1
CPU: (12) arm64 Apple M2 Max
Memory: 464.02 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.17.0
path: ~/.nvm/versions/node/v18.17.0/bin/node
Yarn:
version: 3.6.4
path: ~/.nvm/versions/node/v18.17.0/bin/yarn
npm:
version: 9.6.7
path: ~/.nvm/versions/node/v18.17.0/bin/npm
Watchman:
version: 2024.05.06.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /Users/jay/.gem/ruby/2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11330709
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 11.0.18
path: /usr/bin/javac
Ruby:
version: 2.7.4
path: /Users/jay/.rubies/ruby-2.7.4/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.2
wanted: 0.74.2
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Stacktrace or Logs
(Xcode error)
React-RCTAppDelegate
/Users/jay/tmp/rn74/MyApp/ios/Pods/Headers/Public/ReactCommon/ReactCommon.modulemap
/Users/jay/tmp/rn74/MyApp/ios/Pods/Headers/Public/ReactCommon/ReactCommon.modulemap:1:8 Redefinition of module 'ReactCommon'
Previously defined here
Reproducer
https://github.com/jkoutavas/RN-0-74-2-example
Screenshots and Videos
There's also a reference to this issue on stack overflow: https://stackoverflow.com/questions/78540513/react-native-pod-file-use-modular-headers-throwing-redefinition-of-module-reac/78630743#78630743
Possible duplicates:
- https://github.com/facebook/react-native/issues/44502
- https://github.com/reactwg/react-native-releases/issues/284
Despite the fact two other issues are closed, the workarounds provided there do not work because enabling modular_headers per dependency is not always an option that can be concidered.
As a workaround try to remove use_modular_headers! from your Podfile and apply modular headers only to specific pods
In my case I needed to use modular headers for firebase related pods
pod 'FirebaseCore', :modular_headers => true
pod 'Firebase', :modular_headers => true
pod 'FirebaseCoreInternal', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true
worked for me
As a workaround try to remove
use_modular_headers! from your Podfile and apply modular headers only to specific podsIn my case I needed to use modular headers for firebase related pods
worked for me
We did the same thing and that solved the issue with firebase, but we have another third-party package that is not accepting :modular_headers. So I thought it might be good just to open a general ticket on the subject.
this worked for me:
- added in my pod file
...
pod 'GoogleUtilities', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
# before this line 👇🏼
config = use_native_modules!
...
- And downgrade the "@react-native-firebase/app" to version: 18.6.0
I just add this to pod file
...
# after this line
config = use_native_modules!
use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true
...
I still see people trying to use use_modular_headers in combination with Firebase pods - I need to be very clear (as your friendly neighborhood react-native-firebase maintainer :wave:) that you will have no ability to access support for any problems you have if you do that
The firebase-ios-sdk requires use_frameworks! so react-native-firebase does as well. modular_headers in that sense is a hack workaround that you should not use - you need to find the underlying problem in whatever module isn't compiling correctly with use_frameworks! and fix that.
I still see people trying to use
use_modular_headersin combination with Firebase pods - I need to be very clear (as your friendly neighborhood react-native-firebase maintainer 👋) that you will have no ability to access support for any problems you have if you do thatThe firebase-ios-sdk requires
use_frameworks!so react-native-firebase does as well.modular_headersin that sense is a hack workaround that you should not use - you need to find the underlying problem in whatever module isn't compiling correctly withuse_frameworks!and fix that.
So what can we do?
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
@mikehardy for react-native-firebase pods, I could fix them like this
pod 'FirebaseCore', :modular_headers => true
But how about the react-native pods?
The Swift pod
lottie-react-native-librarydepends uponReact-RCTFabric-library,ReactCodegen-library,RCTTypeSafety-library, andReact-NativeModulesApple-library, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may setuse_modular_headers!globally in your Podfile, or specify:modular_headers => truefor particular dependencies.
Something people need to understand is you have to do use_frameworks, and once you do you dont need modular headers. Those are unsupported and I'll never spend time on them or guess for people.
So my succinct answers are either a) you don't or b) in some unsupported way that will be difficult for you to maintain without support
@mikehardy for
react-native-firebasepods, I could fix them like thispod 'FirebaseCore', :modular_headers => trueBut how about the
react-nativepods?The Swift pod
lottie-react-native-librarydepends uponReact-RCTFabric-library,ReactCodegen-library,RCTTypeSafety-library, andReact-NativeModulesApple-library, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may setuse_modular_headers!globally in your Podfile, or specify:modular_headers => truefor particular dependencies.
I'm getting those issues because of
use_frameworks! :linkage => :static
As per rn firebase iOS instructions
Are you saying there's a way to use use_frameworks! without static?
@akkadaya make sure to add
use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true
before use_react_native.
Thanks @rag, I did that already. it was one of the issues, our Podfile was a mess and I spent a week to fix it