ruby-on-rails - 创建 Ruby On Rails 应用程序时出现 Webpacker 错误

标签 ruby-on-rails ruby webpack rubygems

$ rails 6.0.2 新 sample_app2


    .
    .
    .
    Using web-console 4.0.1
    Using webdrivers 4.1.3
    Using webpacker 4.2.2
    Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
    Use `bundle info [gemname]` to see where a bundled gem is installed.
             run  bundle binstubs bundler
    The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
    Skipped bundle since it already exists.
    If you want to overwrite skipped stubs, use --force.
             run  bundle exec spring binstub --all
    * bin/rake: Spring inserted
    * bin/rails: Spring inserted
           rails  webpacker:install
    Traceback (most recent call last):
        4: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `'
        3: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
        2: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/yarn:23:in `'
        1: from /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:400:in `block in replace_bin_path'
    /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:372: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/

同样在执行之后

 Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/ 

我得到了相同的结果

   

     $ yarn -v
     [DEPRECATION] The trollop gem has been renamed to optimist
     and will no longer be supported. Please switch to optimist
     as soon as possible. Yarn v0.1.1 2011 Jesper Kjeldgaard


    $ ruby -v
         ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]


    $ rails -v
         Rails 6.0.2.1

最佳答案

您将 yarn 安装为 gem https://rubygems.org/gems/yarn这是错误的。 现在你应该这样做:

  1. 卸载这个 gem,gem uninstall yarn

  2. 在 mac os 上 brew install yarn 如果是其他平台则看这里:https://yarnpkg.com/lang/en/docs/install/#debian-stable

  3. 检查版本,应该是这样的:

yarn -v

1.21.1

关于ruby-on-rails - 创建 Ruby On Rails 应用程序时出现 Webpacker 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59410402/

相关文章:

javascript - 定义我自己的 React 事件类型

ruby-on-rails - 无法加载此类文件 -- webrick/httputils

jquery - 在 Rails 应用程序中使用 jQuery 进行 Ajax 调用

ruby-on-rails - 永远不要响应 xhrs 渲染布局

ruby - 如何按字母顺序对数组进行排序?

ruby-on-rails - Rails 中的双多态关联

javascript - ImagesLoaded.js 不适用于 Isotope 和 LazySizes

react-native - react-native 的 bundler 是否通过摇树优化?

ruby-on-rails - rails Assets :precompile during slug for s3 error: Fog provider and directory can't be blank when env are set

ruby - 有没有办法让 resque-web 与 Redis To Go 托管的 redis 实例一起工作?