M1 Mac搭建React Native项目时CocoaPod依赖安装失败
解决CocoaPods安装时ActiveSupport的NoMethodError问题
我尝试了以下操作但均未解决问题:
sudo gem install -n /opt/homebrew/opt/ruby@3.2/bin ffi cocoapodsbrew install cocoapods- 卸载并重新安装旧版本的activesupport
- 通过brew安装所有相关组件
报错信息
✖ Installing CocoaPods dependencies (this may take a few minutes) error bundler: failed to load command: pod (/Users/cadyli/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/bin/pod) /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError) deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator ^^^^^^^^^^^ Did you mean? deprecate_constant from /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>' from <internal:/opt/homebrew/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require' from <internal:/opt/homebrew/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require' from /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top (required)>' from <internal:/opt/homebrew/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require' from <internal:/opt/homebrew/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require' from /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>' from /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/bin/pod:25:in `load' from /Users/ana/Desktop/software projects/ecoexplorer/vendor/bundle/ruby/3.2.0/bin/pod:25:in `<top (required)>' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:58:in `load' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:23:in `run' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:492:in `exec' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:34:in `dispatch' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:28:in `start' from /opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:37:in `block in <top (required)>' from /opt/homebrew/lib/ruby/site_ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors' from /opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:29:in `<top (required)>' from /opt/homebrew/opt/ruby/bin/bundle:25:in `load' from /opt/homebrew/opt/ruby/bin/bundle:25:in `<main>'
问题根源
CocoaPods 1.13.0的依赖声明中,ActiveSupport的版本范围是>= 5.0, < 7.1,但当前环境安装了ActiveSupport 7.1.0——该版本移除了ActiveSupport.deprecator方法,导致调用失败。
解决步骤
通过Gemfile锁定兼容版本
在项目根目录的Gemfile中添加指定版本的ActiveSupport:gem 'activesupport', '~> 7.0.8'然后执行:
bundle install无Gemfile时直接安装兼容版本
先卸载高版本ActiveSupport:gem uninstall activesupport -v 7.1.0再安装兼容版本:
gem install activesupport -v 7.0.8最后重新安装对应版本的CocoaPods:
gem install cocoapods -v 1.13.0清理项目缓存(若使用vendor bundle)
先删除缓存目录:rm -rf vendor/bundle再重新执行bundle安装:
bundle install --path vendor/bundle
内容的提问来源于stack exchange,提问作者Cady Li
相关产品推荐
相关产品推荐

