react-native: Regression -- 0.72 fails to compile on iOS with use_frameworks! :linkage => :static when using pnpm

New Version

0.72.1

Old Version

0.71.11

Build Target(s)

iOS development

Output of react-native info

info Fetching system and libraries information...
System:
  OS: macOS 13.4
  CPU: (10) arm64 Apple M1 Pro
  Memory: 63.72 MB / 16.00 GB
  Shell:
    version: 0.80.0
    path: /Users/imagio/.cargo/bin/nu
Binaries:
  Node:
    version: 18.16.0
    path: ~/Library/Caches/fnm_multishells/62216_1687887822404/bin/node
  Yarn:
    version: 1.22.19
    path: ~/Library/pnpm/yarn
  npm:
    version: 9.7.2
    path: ~/Library/pnpm/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.11.3
    path: /Users/imagio/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: Flamingo 2022.2.1 Patch 2 Flamingo 2022.2.1 Patch 2
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.4.1
    path: /usr/bin/javac
  Ruby:
    version: 3.1.2
    path: /Users/imagio/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.1
    wanted: 0.72.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Issue and Reproduction Steps

Reproduction: https://github.com/evelant/rn072-pnpm-monorepo-ios-frameworks-static-bug

React-native 0.72 fails to compile for iOS when using use_frameworks! :linkage => :static


The following build commands failed:
	CompileC /Users/imagio/Library/Developer/Xcode/DerivedData/testproj-aijjqxpffhriwvdbnbtslrapnlmx/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-utils.build/Objects-normal/arm64/RunLoopObserver.o /Users/imagio/dev/test/node_modules/.pnpm/react-native@0.72.1_@babel+core@7.20.2_@babel+preset-env@7.20.2_react@18.2.0/node_modules/react-native/ReactCommon/react/utils/RunLoopObserver.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-utils' from project 'Pods')
(1 failure)

To reproduce: pnpm install cd apps/testproj/ios USE_FRAMEWORKS=static pod install cd .. pnpm react-native run-ios

About this issue

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

Commits related to this issue

Most upvoted comments

@goguda i am getting this error, i am using npm node_modules/react-native/ReactCommon/react/utils/RunLoopObserver.cpp:10:10: ‘react/debug/react_native_assert.h’ file not found

this is my podfile

# # Resolve react_native_pods.rb with node to allow for hoisting
# require Pod::Executable.execute_command('node', ['-p',
#   'require.resolve(
#     "react-native/scripts/react_native_pods.rb",
#     {paths: [process.argv[1]]},
#   )', __dir__]).strip

pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true

def node_require(script)
    # Resolve script with node to allow for hoisting
    require Pod::Executable.execute_command('node', ['-p',
    "require.resolve(
      '#{script}',
      {paths: [process.argv[1]]},
    )", __dir__]).strip
end

platform :ios, '13.4'
node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')
prepare_react_native_project!


setup_permissions([
  'LocationAccuracy',
  'LocationAlways',
  'LocationWhenInUse',
])

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'vendit' do
  config = use_native_modules!

  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'GoogleMaps', '7.4.0' # <<<<---- I added the '5.1.0' version here
  pod 'Google-Maps-iOS-Utils', '4.2.2' 
  # Flags change depending on the env values.
  flags = get_default_flags()
  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true
  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
#    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  # use_flipper!
  # post_install do |installer|
  #   flipper_post_install(installer)

  #   installer.pods_project.targets.each do |target|
  #     if target.name == "React-Core-AccessibilityResources"
  #       target.remove_from_project
  #     end
  #   end
  # end

  target 'venditTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

and package.json file

{
  "name": "vendit",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "android-clean": "cd android && gradlew clean && gradlew :app:bundleRelease",
    "build-apk": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/ && rm -rf android/app/src/main/res/drawable-* && rm -rf android/app/src/main/res/raw/* && cd android && ./gradlew assembleRelease && cd ..",
    "build-debug-apk": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/debug/ && rm -rf android/app/src/main/res/drawable-* && rm -rf android/app/src/main/res/raw/* && cd android && gradlew assembleDebug && cd ..",
    "iLegacy": "npm i --legacy-peer-deps"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4.5.1",
    "@notifee/react-native": "^7.8.2",
    "@react-native-async-storage/async-storage": "^1.19.3",
    "@react-native-community/blur": "^4.3.2",
    "@react-native-community/cli-platform-android": "^11.3.8",
    "@react-native-community/datetimepicker": "^7.6.0",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-native-firebase/app": "^18.9.0",
    "@react-native-firebase/dynamic-links": "^18.9.0",
    "@react-native-firebase/messaging": "^18.9.0",
    "@react-native-masked-view/masked-view": "^0.2.9",
    "@react-navigation/bottom-tabs": "^6.5.9",
    "@react-navigation/elements": "^1.3.19",
    "@react-navigation/material-top-tabs": "^6.6.12",
    "@react-navigation/native": "^6.1.8",
    "@react-navigation/native-stack": "^6.9.14",
    "@reduxjs/toolkit": "^1.9.6",
    "axios": "^1.5.1",
    "base64-js": "^1.5.1",
    "deprecated-react-native-prop-types": "^5.0.0",
    "i18next": "^23.5.1",
    "lottie-ios": "^4.4.0",
    "lottie-react-native": "^6.6.0",
    "patch-package": "^8.0.0",
    "react": "18.2.0",
    "react-i18next": "^13.2.2",
    "react-native": "0.72.5",
    "react-native-asset": "^2.1.1",
    "react-native-camera": "^4.2.1",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "^2.13.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-maps": "^1.7.1",
    "react-native-modal": "^13.0.1",
    "react-native-modal-popover": "^2.1.3",
    "react-native-navigation-bar-color": "^2.0.2",
    "react-native-pager-view": "^6.2.1",
    "react-native-permissions": "^3.10.1",
    "react-native-popup-menu": "^0.16.1",
    "react-native-qrcode-scanner": "^1.5.5",
    "react-native-qrcode-svg": "^6.3.0",
    "react-native-reanimated": "^3.7.2",
    "react-native-safe-area-context": "^4.7.2",
    "react-native-screens": "^3.25.0",
    "react-native-share": "^10.0.2",
    "react-native-shimmer-placeholder": "^2.0.9",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^13.14.0",
    "react-native-svg-transformer": "^1.1.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.1.6",
    "react-native-vector-icons": "^10.0.1",
    "react-native-webview": "^13.7.0",
    "react-native-wheel-pick": "^1.2.2",
    "react-redux": "^8.1.2",
    "redux": "^4.2.1",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "babel-jest": "^29.2.1",
    "babel-plugin-module-resolver": "^5.0.0",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0"
  },
  "engines": {
    "node": ">=16"
  },
  "resolutions": {
    "react-native-permissions": "^3.8.0"
  },
  "overrides": {
    "react-native-qrcode-scanner": {
      "react-native-permissions": "^3.8.0"
    }
  }
}

Started getting this error after firebase messaging setup

can you try running USE_FRAMEWORKS=static NO_FLIPPER=1 pod install? Flipper is not compatible with use_frameworks (and it will never be).

Thanks @DaniloMladenovic 🙏🏻 I added this to my expo plugins and it worked like a charm ✨

[
  'expo-build-properties',
  {
    ios: {
      // Firebase fix
      extraPods: ['GoogleUtilities', 'FirebaseCore'].map((podName) => ({
        name: podName,
        modular_headers: true,
      })),
    },
  },
]

Adding: pod 'GoogleUtilities', :modular_headers => true # Add missing package pod 'FirebaseCore', :modular_headers => true # Add missing package pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app' # Firebase manual setup

instead of use_frameworks! :linkage => :static helped me.

@evelant how to apply above patch ? when tried with patch-package it says invalid patch file

I facing this issue, the error occurs when using use_frameworks! :linkage => :static in combination with pnpm. I tried two solutions :

Solution 1: Switch to npm or yarn The easiest solution is to switch to npm or yarn instead of pnpm. However, this approach should be avoided in monorepos where it’s important to use the same package manager across the entire repository. => not my choice

Solution 2: Avoid use_frameworks! :linkage => :static and Set Up Manually Instead of using use_frameworks! :linkage => :static, I manually configure the setup. For example, to set up Firebase, follow the official documentation here: Firebase iOS Installation Guide.

After manual setup, I encounter errors regarding missing packages. To fix this, simply add the required dependencies to my Podfile. For Firebase, I add the following:

 pod 'GoogleUtilities', :modular_headers => true # Add missing package
 pod 'FirebaseCore', :modular_headers => true    # Add missing package
 pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app' # Firebase manual setup

By following these steps, I was able to successfully set up Firebase Cloud Messaging (FCM) without further errors.

I also noticed a pull request addressing this issue—hopefully, it will be merged soon, and we won’t need to apply this manual fix anymore.

Here is my environment for reference:

   "react": "18.3.1",
   "react-native": "0.76.2",
   "@react-native-firebase/app": "^21.6.1",
   "@react-native-firebase/messaging": "^21.6.1",

I use monorepo with pnpm: ./

node_module package.json pnpm-workspace.yaml packages

react-native-app (use FCM)

node_module package.json ios

podfile

My Podfile:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'StudentMobileApp' do
  config = use_native_modules!
  $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'GoogleUtilities', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app'

  target 'StudentMobileAppTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

For me, I was placing this line of code: rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path

above target 'commutebuddy' do config = use_native_modules!

It was supposed to be inside.

I get the error: ‘react/debug/react_native_assert.h’ file not found, React-utils/RunLoopObserver. This is my Podfile:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, '13.0'
prepare_react_native_project!

flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled


dynamic_frameworks = [
    'Starscream',
    'iProov',
    'DatadogSDK',
    'SwiftProtobuf',
]
pre_install do |installer|
  installer.pod_targets.each do |pod|
    if !dynamic_frameworks.include?(pod.name)
      puts "Overriding the static_framework? method for #{pod.name}"
      def pod.static_framework?;
        true
      end
      def pod.build_type;
        Pod::BuildType.static_library
      end
    end
  end
end

target 'POK' do
  use_frameworks! :linkage => :static
  config = use_native_modules!
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    :flipper_configuration => FlipperConfiguration.disabled,
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )
  
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  pod 'Google-Maps-iOS-Utils', :git => 'https://github.com/Simon-TechForm/google-maps-ios-utils.git', :branch => 'feat/support-apple-silicon'
  pod 'SRSRadialGradient', :path => '../node_modules/react-native-radial-gradient/ios'
  pod 'FirebaseCoreExtension', :modular_headers => true
  pod 'FirebaseInstallations', :modular_headers => true
  pod 'GoogleDataTransport', :modular_headers => true
  pod 'nanopb', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  $RNFirebaseAsStaticFramework = true

  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path

  target 'POKTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
        end
      end
      installer.generated_projects.each do |project|
        project.targets.each do |target|
          target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
          end
        end
      end
      `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_13_0/' #{installer.sandbox.root}/RCT-Folly/folly/portability/Time.h`
      path = "Pods/Target Support Files/Pods-POK/Pods-POK-frameworks.sh"
      lines = File.readlines(path)
      lines.insert(177, 'install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/hermes.framework"'+"\n")
      File.write(path, lines.join, mode: "w")
  end
end