You need to enable JavaScript to run this app. Mac OS X下React Native Turbo Module安装CocoaPods失败求助
优惠活动
大模型
产品
解决方案
定价
更多

Mac OS X下React Native Turbo Module安装CocoaPods失败求助

React Native新架构安装CocoaPods报错解决

问题重现

错误1:执行RCT_NEW_ARCH_ENABLED=1 bundle exec pod install时

> RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
Could not find cocoapods-1.11.3, cocoapods-core-1.11.3, algoliasearch-1.27.5, typhoeus-1.4.0, json-2.6.2, ethon-0.15.0, ffi-1.15.5 in locally installed gems
Run `bundle install` to install missing gems.

错误2:执行bundle install时

Installing ffi 1.15.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

An error occurred while installing json (2.6.2), and Bundler cannot continue.

In Gemfile:
  cocoapods was resolved to 1.11.3, which depends on
    cocoapods-core was resolved to 1.11.3, which depends on
      algoliasearch was resolved to 1.27.5, which depends on
        json

解决步骤

  • 安装Ruby开发环境依赖
    错误根源是系统缺少Ruby的开发头文件,按系统类型处理:
    • macOS(使用系统Ruby):安装Xcode命令行工具,执行:
      xcode-select --install
      
      安装完成后重新运行bundle install。
    • 若用rbenv/rvm管理Ruby:确保安装对应Ruby版本的开发包,比如rbenv环境下先装ruby-build,再重装对应版本Ruby:
      rbenv install 2.6.x # 替换成你实际需要的Ruby版本号
      
  • 重新执行bundle安装
    依赖准备好后,再次运行:
    bundle install
    
  • 重新执行CocoaPods安装命令
    等bundle安装成功后,运行:
    RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
    

备选方案(上述方法无效时)

  • 更新Gemfile依赖版本:将cocoapods升级到较新的稳定版,避免旧版本依赖的gem存在兼容性问题,修改后重新运行bundle install。
  • 切换Gem镜像加速:若网络问题导致gem安装失败,可切换国内镜像:
    gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
    

内容的提问来源于stack exchange,提问作者Berry Blue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 17:42:16