facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.09k stars 24.07k forks source link

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

Open jkoutavas opened 2 weeks ago

jkoutavas commented 2 weeks ago

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

bomjkolyadun commented 2 weeks ago

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.

krzysiek-mc commented 2 weeks ago

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

jkoutavas commented 1 week ago

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.