前提・実現したいこと
Rails6のアプリケーションをEC2へデプロイする実装をしております。
(EC2へはデプロイ済み
)
デプロイしたアプリケーションをhttp://IPアドレス/
本番環境で立ち上げたところ、We're sorry, but something went wrong.
と表示されてしまいました。
エラーログを確認したところ、Webpackerに関するエラーのようです。
発生している問題・エラーメッセージ
[ec2-user@ip-10-0-0-148 log]$ tail -n 30 production.log [e082a404-5b99-4a05-93a5-945520dfd205] 1: <%= render "shared/header" %> [e082a404-5b99-4a05-93a5-945520dfd205] 2: <%= javascript_pack_tag 'index' %> [e082a404-5b99-4a05-93a5-945520dfd205] 3: [e082a404-5b99-4a05-93a5-945520dfd205] 4: <div id="global-container"> [e082a404-5b99-4a05-93a5-945520dfd205] 5: <div id="main-container"> [e082a404-5b99-4a05-93a5-945520dfd205] [e082a404-5b99-4a05-93a5-945520dfd205] app/views/uploads/index.html.erb:2 I, [2021-07-16T03:13:10.521563 #26995] INFO -- : [aae219c1-daca-4632-a75e-afc86915c664] Started GET "/" for 218.225.198.49 at 2021-07-16 03:13:10 +0000 I, [2021-07-16T03:13:10.522241 #26995] INFO -- : [aae219c1-daca-4632-a75e-afc86915c664] Processing by UploadsController#index as HTML I, [2021-07-16T03:13:10.538558 #26995] INFO -- : [aae219c1-daca-4632-a75e-afc86915c664] Rendered uploads/index.html.erb within layouts/application (Duration: 0.8ms | Allocations: 469) I, [2021-07-16T03:13:10.538644 #26995] INFO -- : [aae219c1-daca-4632-a75e-afc86915c664] Rendered layout layouts/application.html.erb (Duration: 1.0ms | Allocations: 497) I, [2021-07-16T03:13:10.538816 #26995] INFO -- : [aae219c1-daca-4632-a75e-afc86915c664] Completed 500 Internal Server Error in 16ms (ActiveRecord: 0.5ms | Allocations: 998) F, [2021-07-16T03:13:10.539806 #26995] FATAL -- : [aae219c1-daca-4632-a75e-afc86915c664] [aae219c1-daca-4632-a75e-afc86915c664] ActionView::Template::Error (Webpacker can't find index.js in /var/www/rails/locat/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: { } ): [aae219c1-daca-4632-a75e-afc86915c664] 1: <%= render "shared/header" %> [aae219c1-daca-4632-a75e-afc86915c664] 2: <%= javascript_pack_tag 'index' %> [aae219c1-daca-4632-a75e-afc86915c664] 3: [aae219c1-daca-4632-a75e-afc86915c664] 4: <div id="global-container"> [aae219c1-daca-4632-a75e-afc86915c664] 5: <div id="main-container"> [aae219c1-daca-4632-a75e-afc86915c664] [aae219c1-daca-4632-a75e-afc86915c664] app/views/uploads/index.html.erb:2
-
上記のようなエラーが起きており、Webpackerがindex.jsに紐付いていないことが原因になっているみたいです。
-
ローカル環境上では、エラーなどは特に起きておらず、正常に機能しております。
-
また、こちらのエラー以外ではEC2上でunicornやnginxなどにエラーなどは特に起きておりません。
該当のソースコード
[webpacker.yml]
# Note: You must restart bin/webpack-dev-server for changes to take effect default: &default source_path: app/javascript source_entry_path: packs public_root_path: public public_output_path: packs cache_path: tmp/cache/webpacker webpack_compile_output: true # Additional paths webpack should lookup modules # ['app/assets', 'engine/foo/app/assets'] additional_paths: [] # Reload manifest.json on all requests so we reload latest compiled packs cache_manifest: false # Extract and emit a css file extract_css: false static_assets_extensions: - .jpg - .jpeg - .png - .gif - .tiff - .ico - .svg - .eot - .otf - .ttf - .woff - .woff2 extensions: - .vue - .mjs - .js - .sass - .scss - .css - .module.sass - .module.scss - .module.css - .png - .svg - .gif - .jpeg - .jpg development: <<: *default compile: true # Reference: https://webpack.js.org/configuration/dev-server/ dev_server: https: false host: localhost port: 3035 public: localhost:3035 hmr: false # Inline should be set to true if using HMR inline: true overlay: true compress: true disable_host_check: true use_local_ip: false quiet: false pretty: false headers: 'Access-Control-Allow-Origin': '*' watch_options: ignored: '**/node_modules/**' test: <<: *default compile: true # Compile test packs to a separate directory public_output_path: packs-test production: <<: *default # Production depends on precompilation of packs prior to booting for performance. compile: false # Extract and emit a css file extract_css: true # Cache manifest.json for performance cache_manifest: true
試したこと
- 記事で
bundle exec bin/webpack
を導入してみては?とありましたので、試しにこちらのコマンドを実行してみましたが、エラーが発生。
bundler: failed to load command: bin/webpack (bin/webpack) /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/webpacker-5.2.1/lib/webpacker/runner.rb:13:in ``': No such file or directory - yarn (Errno::ENOENT) from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/webpacker-5.2.1/lib/webpacker/runner.rb:13:in `initialize' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/webpacker-5.2.1/lib/webpacker/runner.rb:6:in `new' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/webpacker-5.2.1/lib/webpacker/runner.rb:6:in `run' from bin/webpack:17:in `block in <top (required)>' from bin/webpack:16:in `chdir' from bin/webpack:16:in `<top (required)>' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `load' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `kernel_load' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:28:in `run' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:494:in `exec' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:30:in `dispatch' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:24:in `start' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/exe/bundle:49:in `block in <top (required)>' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors' from /home/ec2-user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.16/exe/bundle:37:in `<top (required)>' from /home/ec2-user/.rbenv/versions/3.0.1/bin/bundle:23:in `load' from /home/ec2-user/.rbenv/versions/3.0.1/bin/bundle:23:in `<main>'
- 上記のエラーでそもそもWebpacerがEC2上で機能していないのではと考えました。
参考記事
こちらの記事を参考に下記のコマンドを実行しました。
$ curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo $ sudo yum install -y yarn
こちらのコマンドでyarn
がインストールされているかもう一度実行してみましたが、エラー内容は変わりませんでした。
補足情報(FW/ツールのバージョンなど)
開発環境
- rubymine
- ruby(3.0.1)
- Ruby on rails (6.1.3.1)
- unicorn (6.0.0)
あなたの回答
tips
プレビュー