質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

0回答

940閲覧

RailsアプリをEC2へデプロイするとエラーが発生

yuu0000

総合スコア4

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2021/07/16 04:34

前提・実現したいこと

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上unicornnginxなどにエラーなどは特に起きておりません。

該当のソースコード

[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)

開発アプリのGithub

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yuu0000

2021/07/17 10:29

ご連絡頂きありがとうございます。 Node.jsはローカル環境にインストールされているのか、もしくはEC2上にインストールされているのかどちらになりますでしょうか?
yu_1985

2021/07/17 23:58

EC2上です。動かしたい環境に入っていないと使えません。
yuu0000

2021/07/18 04:55

node.jsはEC2上にインストール済です。 必要なパッケージなどを一通りインストールされておりました。 [ec2-user@ip-10-0-0-148 ~]$ node -v v12.22.2 [ec2-user@ip-10-0-0-148 ~]$ ruby -v ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux] [ec2-user@ip-10-0-0-148 ~]$ rails -v Rails 6.1.3.1 [ec2-user@ip-10-0-0-148 ~]$ yarn -v 1.22.5 [ec2-user@ip-10-0-0-148 ~]$ bundler -v Bundler version 2.2.23 EC2上以外に原因があるのでしょうか、
yu_1985

2021/07/18 07:07

その状態でbundle installし直すと変わりますかね?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問