React Native 0.75.4执行pod install失败:Podfile报错undefined method `[]' for nil
React Native 0.75.4 + CocoaPods 1.16.2: pod install 失败(undefined method `[]' for nil)
报错指向config = use_native_modules!这行,说明use_native_modules!返回了nil,后续调用config[:reactNativePath]触发了方法不存在的错误。根源在于你的Podfile存在两处关键配置冲突:
- 重复调用
use_frameworks!导致CocoaPods配置状态异常 - 重复加载
react-native/scripts/react_native_pods.rb引发方法冲突
修复步骤
1. 合并use_frameworks!配置
删除重复的use_frameworks!调用,统一配置静态框架:
# 替换原来的两段use_frameworks!代码 linkage = ENV['USE_FRAMEWORKS'] || 'static' Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym $RNFirebaseAsStaticFramework = true
2. 移除重复的react_native_pods.rb加载
Podfile顶部已经通过require加载了该脚本,删除target内部的node_require('react-native/scripts/react_native_pods.rb')调用。
3. (可选)显式指定react-native路径
如果上述修改后仍有问题,可以给use_native_modules!添加路径参数:
config = use_native_modules!(:path => "../node_modules/react-native")
修改后的完整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.4' prepare_react_native_project! # 合并use_frameworks!配置,避免重复调用 linkage = ENV['USE_FRAMEWORKS'] || 'static' Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym $RNFirebaseAsStaticFramework = true ENV['USE_HERMES'] = '0' target 'project' do project 'project.xcodeproj' config = use_native_modules! use_react_native!( :path => config[:reactNativePath], # Fabric is not compatible with use_frameworks as per react-native-firebase doc :fabric_enabled => false, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) 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 node_require('react-native-permissions/scripts/setup.rb') # ⬇️ uncomment wanted permissions setup_permissions([ # 'AppTrackingTransparency', # 'Bluetooth', # 'Calendars', # 'CalendarsWriteOnly', 'Camera', # 'Contacts', # 'FaceID', # 'LocationAccuracy', # 'LocationAlways', 'LocationWhenInUse', # 'MediaLibrary', # 'Microphone', # 'Motion', 'Notifications', # 'PhotoLibrary', # 'PhotoLibraryAddOnly', # 'Reminders', # 'Siri', # 'SpeechRecognition', # 'StoreKit', ]) pod 'RNSecureStorage', :path => '../node_modules/rn-secure-storage/ios/RNSecureStorage.podspec' target 'projectTests' do inherit! :complete # Pods for testing end post_install do |installer| react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, # :ccache_enabled => true ) end end
最后执行清理和重装
# 清理现有Pods和缓存 rm -rf Pods Podfile.lock pod cache clean --all # 重新安装 pod install
内容的提问来源于stack exchange,提问作者Alix Humbert
相关产品推荐
相关产品推荐

