ruby-on-rails - 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 v2.6.0 您应该使用 webpacker 作为默认 rails 6 版本升级 rails 6以及如何升级
希望对你有用
推荐阅读
- python-3.x - 如何为熊猫移动窗口使用for循环
- c++ - std::from_chars 在 MSVC 下无法编译
- android-source - 将OTA下载到Android设备后会发生什么
- android - 如何以编程方式更改约束布局中的约束边距?
- css - CSS 动画,FadeIn / FadeOut 2 连续图像
- javascript - 将表单序列化到 localStorage / 在页面重新加载后恢复它(没有 jQuery)
- python - 如何同时在 CNN 和 Gist 数据上训练 Keras 模型?
- windows - Win10:Cmd批处理文件到Powershell的转换
- react-native - 无法使用带有 React Native 项目的 react-apollo-hooks 使 Mutation 工作
- reactjs - 反应状态值不会更新