新React Native项目Podfile无效,执行pod install报错求助
解决React Native项目Podfile引入Expo autolinking导致的pod install错误
修复步骤
- 打开iOS目录下的
Podfile,删除顶部那行Expo相关的require代码:require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking") - 确保Podfile使用React Native官方的默认配置,标准结构如下(替换成你的项目名称):
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '13.0' target 'YourProjectName' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], :hermes_enabled => false # 如需启用Hermes可改为true ) target 'YourProjectNameTests' do inherit! :complete end use_flipper!() post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end - 在ios目录下重新执行命令:
pod install
可能的原因
- 你可能无意中使用了包含Expo依赖的项目模板初始化RN项目
- 部分第三方RN库可能会自动注入Expo相关的配置代码到Podfile中
- React Native CLI的特定版本可能存在bug,导致错误生成了带有Expo代码的Podfile
内容的提问来源于stack exchange,提问作者realsenorloadenstein
相关产品推荐
相关产品推荐

