首页 > 解决方案 > Yarn -v 给出了这个我无法理解的错误

问题描述

我在我的 Macbook Pro 上设置 rails 开发环境时遇到问题。我之前开发过 Rails (4.0-5.0),此后一直专注于另一个框架(MERN、Jekyll 等)。我决定回到 Rails 来创建一个小应用程序。

所以我会gem install rails(使用 Rails 6.0),它会显示成功但警告我一些错误。

我会得到与 webpack.yml 和 yarn 相关的错误。

我到处谷歌,到处都是 StackOverflow。

经过我的研究,有人建议我通过在 config/ 中创建 webpack.yml 来修复 webpack.yml(不知道为什么在使用时没有创建它rails new myapp)。问题解决了......现在是纱线问题。

所以我这样做了:

➜ myapp git:(master) ✗ yarn -v
Traceback (most recent call last):
    2: from /Users/johntowery/.rbenv/versions/2.6.4/bin/yarn:23:in `<main>'
    1: from /Users/johntowery/.rbenv/versions/2.6.4/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/Users/johntowery/.rbenv/versions/2.6.4/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem yarn (>= 0.a) with executable yarn (Gem::GemNotFoundException)

为什么会yarn -v导致此错误?当我设置 Rails 开发环境时,我得到了各种各样的错误,其中几乎一半与yarn.

我能够使用 启动 rails bundle exec rails server,并且能够访问http://localhost:3000,它按预期显示“耶!你在 Rails 上”。

但是...我需要解决这个yarn问题。我现在需要修复它,所以我以后不必处理它。

任何反馈/答案/建议将不胜感激。

谢谢。

更新:

我确实尝试使用rails new myapp2 --webpack. 这就是我得到的:

Traceback (most recent call last):
    2: from /Users/johntowery/.rbenv/versions/2.6.4/bin/yarn:23:in `<main>'
    1: from /Users/johntowery/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:480:in `block in replace_bin_path'
/Users/johntowery/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:460:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

附加信息

纱线已经通过自制软件和其他方法安装。仍然没有帮助

标签: ruby-on-railsmacosyarnpkgmacos-mojave

解决方案


如果您的 ruby​​ v2.6.0 您应该使用 webpacker 作为默认 rails 6 版本升级 rails 6以及如何升级

希望对你有用


推荐阅读