diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 9ff9871d44ebb8..55bf9dbc7c7285 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -23,6 +23,17 @@ $START_TIME = Time.now.to_i +# `@react-native-community/cli-platform-ios/native_modules` defines +# use_native_modules. We use node to resolve its path to allow for +# different packager and workspace setups. This is reliant on +# `@react-native-community/cli-platform-ios` being a direct dependency +# of `react-native`. +require Pod::Executable.execute_command('node', ['-p', + 'require.resolve( + "@react-native-community/cli-platform-ios/native_modules.rb", + {paths: [process.argv[1]]}, + )', __dir__]).strip + # This function returns the min iOS version supported by React Native # By using this function, you won't have to manually change your Podfile # when we change the minimum version supported by the framework. diff --git a/packages/react-native/template/ios/Podfile b/packages/react-native/template/ios/Podfile index 72f73ee8d3bff4..197230d1d6ea00 100644 --- a/packages/react-native/template/ios/Podfile +++ b/packages/react-native/template/ios/Podfile @@ -1,5 +1,9 @@ -require_relative '../node_modules/react-native/scripts/react_native_pods' -require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' +# 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! @@ -50,6 +54,7 @@ target 'HelloWorld' do # https://github.com/facebook/react-native/blob/main/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)