![](/img/trans.png)
[英]React Native cannot npx init project, cannot find module error
[英]React Native init Project
which ruby
输出 -> /Users/User/.rbenv/shims/ruby
ruby -v
输出 -> ruby 2.7.5p203(2021-11-24 修订版 f69aeb8314)[x86_64-darwin21]
which bundle
输出 -> /Users/User/.rbenv/shims/bundle
bundle -v
输出 -> Bundler 版本 2.1.4
但问题是npx react-native init MyProject
输出 -> ✖ Installing Bundler error Bundler::RubyVersionMismatch: Your Ruby version is 2.6.10, but your Gemfile specified 2.7.5
可能发生的情况是npx react-native init MyProject
正在对 Bash 进行子壳化,而您没有配置 rbenv。 当它尝试从 Bash 运行ruby
时,它会在$PATH
中查找并找到默认的 macOS 版本 Ruby -- 2.6.10 -- 并出错。
这在react-native 存储库中进行了彻底讨论,其中有很多解决方案,但归结为react-native init
没有找到 Ruby 的正确版本,无论出于何种原因。 您可以通过自己完成init
过程的失败部分来绕过它:
cd MyProject
bundle install
cd ios && bundle exec pod install
较长版本的解决方案是也为 Bash 配置 rbenv ,但这不是必需的,因为您可能只使用上面的解决方法:
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bash_profile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.