LoginSignup
21
11

More than 1 year has passed since last update.

Rails 'error Command "webpack" not found.'について

Last updated at Posted at 2022-02-19

内容

ターミナルにて

$ rails s

をした際、

Webpacker::Manifest::MissingEntryError
Webpacker can't find application in /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_pack_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

とでてしまう。

webpackerをinstallし、下記のコマンドを打っても

$ rails webpacker:compile
Compiling...
Compilation failed:
yarn run v1.22.10
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


error Command "webpack" not found.

と出てしまった。

解決策

1,gemファイル内のwebpackerを最新のものにする。

Gemfile
gem 'webpacker',    '~> 5.0'

2,その後に、bundleを行う。

bundle

3,webpackerのinstallを再度行う。その際に、conflictを起こして何か聞かれてもYで押し切る。

bundle exec rails webpacker:install

4,その後、webpackerをcompileする。

bundle exec rails webpacker:compile

再度rails sをするとerrorが直っている。
以上。

参考

(https://techblg.app/articles/handle-webpacker-manifest-missing-entry-error/)

21
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
11