5
2

More than 1 year has passed since last update.

Railsでpublic/packs/manifest.jsonの中身がないというエラーが出てハマった(AWSデプロイ時)

Posted at

エラー内容

AWSにRailsアプリをgit cloneでデプロイした時に以下のエラーでどハマりしました。

 ActionView::Template::Error (Webpacker can't find application.js in /var/www/rails/アプリ名/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:
{
}
):

解決方法1

以下の記事のように、webpackerをコンパイルすることです。

ローカルの.gitignoreファイルに/public/packsが含まれていたため、Heroku上では問題なく動いていてもGitHubからcloneしたAWS上ではコンパイルが必要でした。
ちなみにrails webpacker:compileコマンドは、完了するまでにかなり時間がかかったので、根気よく待ちましょう。(私は初めてこのコマンドを入力した時に、時間がかかりすぎて固まったと勘違いし強制終了させてしまったような気がします...。)

解決方法2

私の場合は「解決方法1」ではエラー内容が変わらず、ここでどハマりしました。
cat /public/packs/manifest.jsonでファイルの内容を確認したところ、記述されており、コンパイルされているもののエラー文は変わらずYour manifest contains:{}と表示されていました。
こちらの解決方法は、「アプリケーションサーバーの再起動」です。(私の場合は、ハマりすぎて見当違いにファイルをいじってしまい、rails webpacker:compileコマンドでエラーを吐くようになってしまったためgit cloneし直しました。その後「解決方法1」を行ったところ、勝手にアプリケーションサーバーが落ちたため起動し直しました。)

Unicornを使っているので、こちらを再起動します。
再起動は、以下の記事を参考にしました。

これでなんとかエラーを解消することができました!!!

5
2
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
5
2