react-native icon indicating copy to clipboard operation
react-native copied to clipboard

React native pod file use_modular_headers! throwing Redefinition of module 'ReactCommon' error

Open jkoutavas opened this issue 1 year ago • 4 comments

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

jkoutavas avatar Jun 17 '24 02:06 jkoutavas

Possible duplicates:

  1. https://github.com/facebook/react-native/issues/44502
  2. 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.

dimaosipa avatar Jun 20 '24 23:06 dimaosipa

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

krzysiek-mc avatar Jun 21 '24 13:06 krzysiek-mc

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

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.

jkoutavas avatar Jun 21 '24 17:06 jkoutavas

this worked for me:

  1. added in my pod file
...
pod 'GoogleUtilities', :modular_headers => true  
pod 'FirebaseCore', :modular_headers => true

# before this line 👇🏼
config = use_native_modules!
...
  1. And downgrade the "@react-native-firebase/app" to version: 18.6.0

iamdperez avatar Jul 09 '24 05:07 iamdperez

I just add this to pod file

...
# after this line
config = use_native_modules!

use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true
...

MariaPereiraMindera avatar Aug 19 '24 16:08 MariaPereiraMindera

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.

mikehardy avatar Jan 31 '25 23:01 mikehardy

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 👋) 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.

So what can we do?

HubertRyanOfficial avatar Mar 07 '25 06:03 HubertRyanOfficial

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.

react-native-bot avatar Sep 04 '25 05:09 react-native-bot

@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-library depends upon React-RCTFabric-library, ReactCodegen-library, RCTTypeSafety-library, and React-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 set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies.

akkadaya avatar Sep 08 '25 14:09 akkadaya

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-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-library depends upon React-RCTFabric-library, ReactCodegen-library, RCTTypeSafety-library, and React-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 set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies.

mikehardy avatar Sep 08 '25 14:09 mikehardy

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 avatar Sep 08 '25 14:09 akkadaya

@akkadaya make sure to add

  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true 

before use_react_native.

Rag0n avatar Sep 24 '25 11:09 Rag0n

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

akkadaya avatar Sep 24 '25 12:09 akkadaya