简体   繁体   English

React Native 初始化项目

[英]React Native init Project

which ruby outputs -> /Users/User/.rbenv/shims/ruby which ruby输出 -> /Users/User/.rbenv/shims/ruby

ruby -v outputs -> ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin21] ruby -v输出 -> ruby 2.7.5p203(2021-11-24 修订版 f69aeb8314)[x86_64-darwin21]

which bundle outputs -> /Users/User/.rbenv/shims/bundle which bundle输出 -> /Users/User/.rbenv/shims/bundle

bundle -v outputs -> Bundler version 2.1.4 bundle -v输出 -> Bundler 版本 2.1.4

but the problem is that npx react-native init MyProject outputs -> ✖ Installing Bundler error Bundler::RubyVersionMismatch: Your Ruby version is 2.6.10, but your Gemfile specified 2.7.5但问题是npx react-native init MyProject输出 -> ✖ Installing Bundler error Bundler::RubyVersionMismatch: Your Ruby version is 2.6.10, but your Gemfile specified 2.7.5

What's likely happening is that npx react-native init MyProject is sub-shelling into Bash where you do not have rbenv configured.可能发生的情况是npx react-native init MyProject正在对 Bash 进行子壳化,而您没有配置 rbenv。 When it tries to run ruby from Bash it looks in $PATH and finds the default macOS version of Ruby -- 2.6.10 -- and errors out.当它尝试从 Bash 运行ruby时,它会在$PATH中查找并找到默认的 macOS 版本 Ruby -- 2.6.10 -- 并出错。

This is discussed thoroughly in the react-native repo where there are many solutions, but what it boils down to is react-native init is not finding the right version of Ruby, for whatever reason.这在react-native 存储库中进行了彻底讨论,其中有很多解决方案,但归结为react-native init没有找到 Ruby 的正确版本,无论出于何种原因。 You can bypass that by completing the failing part of the init process yourself with:您可以通过自己完成init过程的失败部分来绕过它:

cd MyProject
bundle install
cd ios && bundle exec pod install

The longer version of the solution is to configure rbenv for Bash as well, but this isn't necessary as you can likely use just the workaround above:较长版本的解决方案是也为 Bash 配置 rbenv ,但这不是必需的,因为您可能只使用上面的解决方法:

echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bash_profile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM