7
4

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.

【Rails】Webpacker::Manifest::MissingEntryError時の対処法【react-rails gem】

Last updated at Posted at 2021-03-30

rails serverを起動すると、「Webpacker::Manifest::MissingEntryError」というエラーが表示されてしまいました。(Rails v6.0.3) Railsの初期画面の「yay!」は表示されますが、表示させたいURLだと下記エラーになります。

なお、react-rails gemを追加しております。

image.png

この記事の解決法を実施しましたが、解決しませんでした。

ターミナル上では下記エラーが表示されました。

ターミナル
Processing by StaticPagesController#home as HTML
  Rendering static_pages/home.html.erb within layouts/application
  Rendered static_pages/home.html.erb within layouts/application (Duration: 0.6ms | Allocations: 230)
[Webpacker] Compiling…
[Webpacker] Compilation failed:
[webpack-cli] Failed to load '/home/ubuntu/environment/プロジェクト名/config/webpack/development.js' config
[webpack-cli] TypeError: Cannot read property 'toWebpackConfig' of undefined
    at Object.<anonymous> (/home/ubuntu/environment/プロジェクト名/config/webpack/development.js:5:30)
    at Module._compile (/home/ubuntu/environment/プロジェクト名/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (/home/ubuntu/environment/プロジェクト名/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at loadConfig (/home/ubuntu/environment/プロジェクト名/node_modules/webpack-cli/lib/webpack-cli.js:1322:31)
    at Promise.all.options.config.map (/home/ubuntu/environment/プロジェクト名/node_modules/webpack-cli/lib/webpack-cli.js:1409:74)

Completed 500 Internal Server Error in 1939ms (ActiveRecord: 0.0ms | Allocations: 1189337)


  
ActionView::Template::Error (Webpacker can't find application in /home/ubuntu/environment/プロジェクト名/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


解決しなかったコマンド
brew install yarn

rails install yarn

一応、こちらも試しましたが、解決せず。

ターミナル
yarn

yarn install  

yarn upgrade 

解決方法

webpackerの再インストールなどいろいろやりましたが、下記コードをエラーで引っかかっていたコードを下記コードに書き換えたら、動作するようになりました。
削除したコード(app/views/layouts/application.html.erb)
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
追加したコード(app/views/layouts/application.html.erb)
<%= javascript_pack_tag    'application' %>
app/views/layouts/application.html.erbの全体(念のため)
<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag    'application', media: 'all',
                               'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag    'application' %> #この一行を追加
    <%= render 'layouts/shim' %>
  </head>

  <body>
    <%= render 'layouts/header' %>
    <%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
    <%= yield %>
    <%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
    <%= render 'layouts/footer' %>
  </body>
</html>

参考

【Rails6】Webpacker::Manifest::MissingEntryErrorが出たときの対処法 https://qiita.com/masatwork/items/1b5d190cc76f5eeffbb7

[rails6]<%= javascript_pack_tag ~ %> を記述すると heroku で エラーが出る
https://teratail.com/questions/297075

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?