首页 > 解决方案 > Rails:Vanilla Rails 6.0 错误命令“webpack”未找到

问题描述

系统:

Ruby:2.6.3p62 (rvm)
Rails:6.0
操作系统:macOS 10.14.6

设置

一个全新的 Rails 6.0 应用程序:

$ rails new testshop2
$ cd testshop2
$ rails g controller Page index
$ rails s
=> Booting Puma
=> Rails 6.0.0 application starting in development 
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

当我浏览到“ http://localhost:3000/page/index ”时,系统会出现此错误:

Started GET "/page/index" for ::1 at 2019-09-23 17:06:12 +0200
  (0.4ms)  SELECT sqlite_version(*)
Processing by PageController#index as HTML
  Rendering page/index.html.erb within layouts/application
  Rendered page/index.html.erb within layouts/application (Duration: 1.8ms | Allocations: 206)
[Webpacker] Compiling…
[Webpacker] Compilation failed:
error Command "webpack" not found.

Completed 500 Internal Server Error in 2021ms (ActiveRecord: 0.0ms | Allocations: 640080)



ActionView::Template::Error (Webpacker can't find application in /Users/stefan/Github/sandbox/testshop2/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
  unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
    6:     <%= csp_meta_tag %>
    7: 
    8:     <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    9:     <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
    10:   </head>
    11: 
    12:   <body>

app/views/layouts/application.html.erb:9

我怎样才能解决这个问题?它说error Command "webpack" not found.但 Rails 不应该自动安装所有需要的东西吗?

标签: ruby-on-railswebpackruby-on-rails-6

解决方案


我遇到了同样的问题。并尝试bundle exec rails webpacker:install按照@AFOC 的回答建议运行。然后我意识到我的节点版本与 rails/webpacker 不兼容。然后使用节点 12.x。有用。

我也通过删除整个应用程序重试,再次创建应用程序,没有再次遇到问题,它第一次工作。所以就我而言,它是节点版本。


推荐阅读