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

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

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

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Ruby on Rails

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

Q&A

1回答

3331閲覧

heroku runrake db:migrateを行うとNo rakefile foundのエラーが表示されてデプロイできない

psaq

総合スコア0

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2021/09/29 09:40

ローカル環境で作ったRuby on railsのポートフォリオをGithubを通してHerokuへデプロイしようとしているのですが、heroku run rake db:migrateを行うと以下のエラーメッセージが表示され、Herokuへデプロイすることができません。

rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (requred)>' (See full trace by running task with --trace)

Rakefileに関してはすでに該当のアプリケーション内に存在しており、rails newコマンドで作成したappファイルやconfigファイルなどと同じ階層に存在しています。Rakefileの内容は

require_relative "config/application" Rails.application.load_tasks

となっています。

No Rakefile foundの下に記述されている

/usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (requred)>'

が問題になっているのかと思っているのですが、どのようにしたらコマンドを成功させられるのかが分かりません。どなたか解決策を教えてくださる方がいましたらお願いいたします。

ちなみに

/usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (requred)>'

について検索したところ、

$ gem environment

で-GEM PATHSの欄に/usr/share/rubygems-integration/が存在する方がいたので同じようにgem environmentを試したところ、私の欄は

- GEM PATHS: - C:/Ruby30-x64/lib/ruby/gems/3.0.0 - C:/Users/ユーザー名/.local/share/gem/ruby/3.0.0

となっていました。

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

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

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

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

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

neko_daisuki

2021/09/29 12:10

heroku run ls とすると返ってくるファイル一覧の中に Rakefile はありますか?
psaq

2021/09/29 13:29

やってみたところ $ heroku run ls Running ls on [herokuで用いているURL]... starting, run.5533 (Free) Running ls on [herokuで用いているURL]... connecting, run.5533 (Free)Running ls on [herokuで用いているURL]... up, run.5533 (Free) という結果になりました。 調べてみたところ実行のコマンドのようですが、Rakefileは返ってきていないですね...
neko_daisuki

2021/09/29 13:34

heroku run rake db:migrate の前に、「Githubを通してHerokuへデプロイ」していると思うのですが、 これが失敗している気がします。なにかエラーらしきものは出ませんでしたか?
neko_daisuki

2021/09/29 13:39

heroku run ls は heroku で ls (ファイル一覧を取得)を実行しています。 それが空っぽということはデプロイに失敗しているのではないかと。
psaq

2021/09/29 14:06

申し訳ありません、Herokuのダッシュボードをよく確認しておらず、先ほど確認したところBuild failedとなっていました。 logの中から原因になっていそうな記述を探してみたところ、途中で rake aborted! NameError: uninitialized constant Rack::MiniProfiler Did you mean? MiniMime というエラーが発生していました。私の確認不足によるもので申し訳ありませんでした。こちらでもこのエラーについてもう一度調べ直します。
psaq

2021/09/30 13:57

このエラーコードについて検索したところ、 https://stackoverflow.com/questions/31133883/uninitialized-constant-rackminiprofiler-on-staging というページにて似たような問題に対するものが書かれていましたが、このページを参考に質問者側のコマンドを試してみても解決には至りませんでした。 回答者側の答えは2人とも具体的にどのようなコマンドを入力すればいいのかが分からず、試せてすらいません。
psaq

2021/09/30 14:08

質問者側のコマンドはApplicationControllerで rack-mini-profilerを使用していないので、rack_profiler.rbにのみコマンドを追加しています。
neko_daisuki

2021/09/30 14:17

rake aborted! とありますが、rake がどんなタスクを実行しようとしたのかログから分かりますか? また、Gemfile に gem 'rack-mini-profiler' の行はありますか? VSCode を使っているなら、MiniProfiler で検索すると何かヒットしませんか?
psaq

2021/09/30 23:27

logでは様々なものがFetchingとInstallingを繰り返された後、 Bundle complete! 16 Gemfile dependencies, 56 gems now installed. Gems in the groups 'development' and 'test' were not installed. Bundled gems are installed into `./vendor/bundle` Bundle completed (143.54s) Cleaning up the bundler cache. Removing bundler (2.2.21) -----> Installing node-v12.16.2-linux-x64 -----> Installing yarn-v1.22.4 -----> Detecting rake tasks -----> Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! NameError: uninitialized constant Rack::MiniProfiler Did you mean? MiniMime というようになっています。Detecting以降のログが今回に関係していると思います。 Gemfileにrack-mini-profilerの行は存在し、 group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md gem 'rack-mini-profiler', '~> 2.0' end というようにgroup :development doの中に入っています。 また、MiniProfilerで検索すると同じ名前のフォルダがヒットし、中にはmp_timersとmp_viewsという名前のファイルが入っています。
neko_daisuki

2021/10/01 03:53

Did you mean? MiniMime の次の行にエラーが出た個所が書いてありませんか?
psaq

2021/10/01 10:59

申し訳ありませんでした、そちらを書かなければならなかったのですね。 Did you mean? MiniMiMeの次の行から最後までは /tmp/build_c52f8dfd/config/initializers/rack_profile.rb.rb:1:in `<main>' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:681:in `block in load_config_initializer' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.4.1/lib/active_support/notifications.rb:205:in `instrument' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:680:in `load_config_initializer' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:633:in `each' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/engine.rb:633:in `block in <class:Engine>' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `instance_exec' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `run' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:61:in `block in run_initializers' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:50:in `each' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:50:in `tsort_each_child' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/initializable.rb:60:in `run_initializers' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/application.rb:391:in `initialize!' /tmp/build_c52f8dfd/config/environment.rb:5:in `<main>' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/application.rb:367:in `require_environment!' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/application.rb:533:in `block in run_tasks_blocks' /tmp/build_c52f8dfd/vendor/bundle/ruby/3.0.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define' Tasks: TOP => environment (See full trace by running task with --trace) ! ! Precompiling assets failed. ! ! Push rejected, failed to compile Ruby app. ! Push failed というようなことが書かれています。
neko_daisuki

2021/10/01 11:06

config/initializers/rack_profile.rb の中で Rack::MiniProfiler を参照していませんか? gemfile でそう指定しているので production 環境ではこの定数は存在しないはずですが、 参照してしまっているんじゃないかと思います。
psaq

2021/10/01 12:22

rack_profile.rbのファイルの中にはstackoverflowの似たような質問を見て追加した if Rails.env == 'development' require 'rack-mini-profiler' Rack::MiniProfiler.authorize_request #if current_user.admin? end の記述の他に Rack::MiniProfiler.config.position = 'bottom-right' という記述が書かれていました。 ちなみにファイル内の記述をすべて削除してデプロイしたのですが、同じように rake aborted! remote: NameError: uninitialized constant Rack::MiniProfiler remote: Did you mean? MiniMime のエラーが出ました。
neko_daisuki

2021/10/01 12:32

削除しても同じエラーになるのはおかしいですね。 そのエラーも config/initializers/rack_profile.rb.rb で発生しているのでしょうか?
neko_daisuki

2021/10/01 12:33

github に push していると思うので、ブラウザでリポジトリを開いてみて、 rack_profile.rb が含まれてないか確認してみると良いかもしれません。
psaq

2021/10/01 12:49

申し訳ありませんでした。さっきの削除は自分のパソコンで行っていました。 しかし、github上に存在するrack_profile.rb内の記述を削除しても、同じエラーが出てしまいました。
neko_daisuki

2021/10/01 13:46

rack_profile.rb でエラーが発生しているのなら、デプロイの作業に問題があるのかもしれません。 問題なければ github の URL を貼っていただけたらこちらでデプロイしてみます。 rack_profile.rb 以外であればそちらを解決しましょう。
psaq

2021/10/01 14:29

正直、今の自分のデプロイに関する知識ではこの問題を解決できそうにないと判断したので、お願いいたします。 https://github.com/KS0908/sk12498 です。
neko_daisuki

2021/10/01 14:44

git clone してそのまま heroku に push したらデプロイできました。 heroku が rake_profile.rb を含む古いコミット、あるいはブランチを参照してしまっているのかも・・・
neko_daisuki

2021/10/01 14:47

heroku のダッシュボードから Deployment method を いったん Heroku Git に変更してデプロイしてみてください。 git push heroku master です。
psaq

2021/10/02 04:25

Deployment methodは元からHeroku Gitでした。 git cloneをしてからもう一度git push heroku masterをしてみたりもしたのですが、やはり同じエラーがでてしまいます。 最終的な手段としてはrack-mini-profilerのファイルと関連する記述の削除しかないのでしょうか...
neko_daisuki

2021/10/02 05:04

僕ならアプリを削除しても問題ないなら削除して新たに heroku create してやり直してみます。
psaq

2021/10/02 06:37

GemFileからrack-mini-profilerの記述を削除して、rack.profile.rbを削除しても同じエラーになりました...
neko_daisuki

2021/10/02 07:36

こちらの環境では rack_profile.rb が空であればデプロイに成功します。 失敗するのは heroku が壊れているか、デプロイのやり方が間違っているかのどちらかだと思います。
psaq

2021/10/02 08:38

似たような事例を探して検索していたところ、 https://yoji4910.hatenablog.com/entry/2019/09/14/184344 という記事を見つけましてheroku run gem listを入力したところ、rack-mini-profilerらしき文字が見当たらなかったので、この記事に書いてあるようにdevelopment doからrack-mini-profilerを外した時点でbundle installを行いました。この後heroku run gem listを行ったところ、 benchmark (default: 0.1.0) bigdecimal (default: 2.0.0) bundler (default: 2.1.2) cgi (default: 0.1.0) csv (default: 3.1.2) date (default: 3.0.0) dbm (default: 1.1.0) delegate (default: 0.1.0) did_you_mean (default: 1.4.0) etc (default: 1.1.0) fcntl (default: 1.0.0) fiddle (default: 1.0.0) fileutils (default: 1.4.1) forwardable (default: 1.3.1) gdbm (default: 2.1.0) getoptlong (default: 0.1.0) io-console (default: 0.5.3) ipaddr (default: 1.2.2) irb (default: 1.2.1) json (default: 2.3.0) logger (default: 1.4.2) matrix (default: 0.2.0) minitest (5.13.0) mutex_m (default: 0.1.0) net-pop (default: 0.1.0) net-smtp (default: 0.1.0) net-telnet (0.1.1) observer (default: 0.1.0) open3 (default: 0.1.0) openssl (default: 2.1.2) ostruct (default: 0.2.0) power_assert (1.1.7) prime (default: 0.1.1) pstore (default: 0.1.0) psych (default: 3.1.0) racc (default: 1.4.16) rake (13.0.1) rdoc (default: 6.2.1) readline (default: 0.0.2) readline-ext (default: 0.1.0) reline (default: 0.1.2) rexml (default: 3.2.3) rss (default: 0.2.8) sdbm (default: 1.0.0) singleton (default: 0.1.0) stringio (default: 0.1.0) strscan (default: 1.0.3) test-unit (3.3.5) timeout (default: 0.1.0) tracer (default: 0.1.0) uri (default: 0.10.0) webrick (default: 1.6.0) xmlrpc (0.3.0) yaml (default: 0.1.0) zlib (default: 1.1.0) となったのですが、この後git push heroku masterをしても同じエラーが出てしまいました。 やはりインストールできていないのでしょうか...?
neko_daisuki

2021/10/02 09:18

なんだかよく分かりません。 問題を整理すると、production 環境で Rack::MiniProfiler はインストールしません。 なので gem list に表示されないのは正しい状態です。 Rack::MiniProfiler が存在しない production 環境で 定数 Rack::MiniProfiler を参照ようとしてエラーになっています。 Rack::MiniProfiler を参照しようとしているファイルは rack_profile.rb で、 これを修正しても何故かエラーになります。 なので (A)heroku がおかしいか、(B)デプロイのやり方が間違っているかのどちらかを疑っています。 (B) じゃないか確認するため以下を実行してください (1) git show HEAD:config/initializers/rake_profile.rb.rb で空か確認 (2) git branch で master か確認 (3) git push heroku master
psaq

2021/10/02 09:36

実行した結果以下のようになりました。 $ git show HEAD:config/initializers/rake_profile.rb.rb fatal: path 'config/initializers/rake_profile.rb.rb' does not exist in 'HEAD' $ git branch * master $ git push heroku master 今までと同じ remote: rake aborted! remote: NameError: uninitialized constant Rack::MiniProfiler remote: Did you mean? MiniMime となりました。
neko_daisuki

2021/10/02 09:55

ごめんなさい、ファイル名間違ってました。 git show HEAD:config/initializers/rack_profile.rb.rb ですね
psaq

2021/10/02 09:59

$ git show HEAD:config/initializers/rack_profile.rb.rb Rack::MiniProfiler.config.position = 'bottom-right' 以前削除する前の記述が出てきました。空にはなっていないようです。
neko_daisuki

2021/10/02 10:35

それが原因ですね。git status で確認して変更を反映させてください。
psaq

2021/10/02 12:00

git add→git commitした後git push heroku masterをすると remote: yarn install v1.22.4 remote: [1/4] Resolving packages... remote: [2/4] Fetching packages... 以下略して Released v4 remote: https://sk124mario98.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/sk124mario98.git * [new branch] master -> master となったので、git push heroku masterは成功したようです。 しかし、その次のheroku run rake db:migrateを行うとNo Rakefile foundの代わりに rake aborted! ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? というエラーが出てしまいました。 その後/app/vendor/...というのが何行も続いた後に
psaq

2021/10/02 12:01

途中で投稿してしまいました。 /app/vendor/という文が何行も続いた後に Caused by: PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? という先ほどと同じような記述が書かれています。
psaq

2021/10/02 12:12

エラーの解決法について調べてみましたがbrewコマンドを使うものばかりでした... brewコマンドが使えないので、(Mac専用のコマンドだったと思うのですが私の開発環境がWindows)また詰まってしまっています。
psaq

2021/10/02 12:18

情報ありがとうございます。すぐに取りかかります。
psaq

2021/10/02 13:08

記事の手順に従い、遂にデプロイに成功しました! Ruby初心者なもので手間を取らせてしまい大変申し訳ありませんでした。今までお付き合いくださりありがとうございました! 追記:実はheroku run rake db:migrateの後、ページは表示されたのですがApplication errorが発生していました。これは自己解決できたのですが、後に同じエラーに会う可能性のある人のために解決法を記載します。 ログからエラーを探したところ、expected file /app/app/controllers/about_controller.rb to define constant AboutController, but didn't (Zeitwerk::NameError)というエラーが見つかりました。 次にheroku logs –tailでエラーを探すとat=error code=H10というコードが見つかりました。ここで以下の記事 https://qiita.com/gonza_kato_atsushi/items/bd52462e2a54968ba57f に従いconfig/application.rbに class Application < Rails::Application config.load_defaults 6.0 #下の一行を追加する config.autoloader = :classic end と記述し、git add→git commit→git push heroku master→heroku run rake db:migrate と入力することでデプロイ画面が表示されました。
neko_daisuki

2021/10/02 13:40

ファイル名とそこで定義されている定数名が合っていない時のエラーですね。 ともかくおめでとうございます。お疲れさまでした。
guest

回答1

0

rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (requred)>' (See full trace by running task with --trace)

エラーになるコマンドを実行してるディレクトリの場所を確認していいですか?
プロジェクトの下じゃないといけないと思います。

cd your_project_path

投稿2021/10/18 05:53

heroyct

総合スコア434

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問