我尝试在 React Native 中创建一个新项目:
npx react-native@latest init myApp
> gem which cocoapods
/Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb
创建项目时我得到这个:
Installing CocoaPods dependencies (this may take a few minutes)
error bundler: failed to load command: pod (/Users/nameUser/Desktop/proj/myApp/vendor/bundle/ruby/3.2.0/bin/pod)
/Users/nameUser/Desktop/proj/myApp/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/nameUser/Desktop/proj/myApp/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:/Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from <internal:/Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from /Users/nameUser/Desktop/proj/myApp/vendor/bundle/ruby/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top (required)>'
from <internal:/Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from <internal:/Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from /Users/nameUser/Desktop/proj/myApp/vendor/bundle/ruby/3.2.0/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>'
from /Users/nameUser/Desktop/proj/myApp/vendor/bundle/ruby/3.2.0/bin/pod:25:in `load'
from /Users/nameUser/Desktop/proj/myApp/vendor/bundle/ruby/3.2.0/bin/pod:25:in `<top (required)>'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:492:in `exec'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/cli.rb:28:in `start'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:37:in `block in <top (required)>'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
from /Users/nameUser/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:29:in `<top (required)>'
from /Users/nameUser/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
from /Users/nameUser/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'
✖ Installing CocoaPods dependencies (this may take a few minutes)
error Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/environment-setup?os=macos&platform=android and follow the React Native CLI QuickStart guide for macOS and iOS.
你能帮我一下吗?
我在旧版本的 Ruby 下也遇到过这种情况。我认为这与最近对
react-native
存储库的提交有关:
https://github.com/facebook/react-native/commit/ce39931bc2b02f13cbc5751ba4d4a6dbc07bc91a
我想我已经找到了解决这个问题的方法(除非有一些新的先决条件没有记录,我不熟悉 Ruby 生态系统)
检查
@react-native-community/cli
包后,失败的命令是 bundle exec pod install
。
如果您重新运行 init 项目命令,让它失败,然后
cd YourProjectName/ios/ && pod install
,它应该为您工作,就像官方安装程序成功完成一样。
从那里您可以
yarn start
并在 iOS、Android 等上运行应用程序。