1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ActionView::Template::Error: Webpacker can't find application in..のデバッグ

Last updated at Posted at 2021-03-15

#目次

  • エラー内容
  • 使用環境
  • 対処法
  • 終わりに

#エラー内容
Railsチュートリアル第3章にて、Railsサーバーを立ち上げて (http://localhost:3000/static_pages/home) を実行したところ、以下のようなエラーが出没しました。。

ActionView::Template::Error (Webpacker can't find application in /Users/yuuu/environment2/sample_app/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

#使用環境
macOS BigSur 11.2.2
ruby 2.6.6
Rails 6.0.3
webpacker 4.0.7

#対処法
webpackをコンパイルすれば解決するとのことだったので以下のコマンドを実行しましたがエラーが出ました。

$ bin/webpack
[webpack-cli] Failed to load '/Users/yuuu/environment2/sample_app/config/webpack/development.js' config
[webpack-cli] TypeError: Cannot read property 'toWebpackConfig' of undefined
    at Object.<anonymous> (/Users/yuuu/environment2/sample_app/config/webpack/development.js:5:30)
    at Module._compile (/Users/yuuu/environment2/sample_app/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (/Users/yuuu/environment2/sample_app/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at loadConfig (/Users/yuuu/environment2/sample_app/node_modules/webpack-cli/lib/webpack-cli.js:1158:31)
    at /Users/yuuu/environment2/sample_app/node_modules/webpack-cli/lib/webpack-cli.js:1245:74
    at Array.map (<anonymous>)

調べたところ、application.html.erbで出ているエラーの以下の一文をコメントアウトしたところ、無事にviewが描画されました。

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

#終わりに
JavaScript系のエラーは詳しくなかったのでかなり骨が折れました、。根本的な解決になっているかわからないので、原因が分かり次第追記させていただければと思います!(ふぅ。)

1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?