LoginSignup
6
0

More than 3 years have passed since last update.

cannot load such file -- rake (LoadError)やcannot load such file -- bootsnap/setup (LoadError)と出てherokuへのデプロイに失敗する

Last updated at Posted at 2021-01-29

1.最終的にとった解決策

herokuが対応しているbundlerのバージョンが2.1.4までだったため、Gem.lockを一度削除し、改めてbundler2.1.4をインストール

2.環境及び問題

ruby 2.6.6
rails 6.1.1

railsチュートリアルを進める途中、ローカル環境にrubyの開発環境を整えたが、herokuへのデプロイだけがうまく行っていなかった。
ローカル環境に移行した3章の最初のデプロイがうまくいかずつまずいたが、1章のデプロイも同じエラーでできなかった。
エラーメッセージは以下のとおり。

remote:  !     Could not detect rake tasks
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
remote:  !     and using the production group of your Gemfile.
remote:  !     /tmp/build_08768f79/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
remote:  !     from /tmp/build_08768f79/config/boot.rb:4:in `<top (required)>'
remote:  !     from /tmp/build_08768f79/bin/rake:3:in `require_relative'
remote:  !     from /tmp/build_08768f79/bin/rake:3:in `<main>'

Gemfileは以下のとおりで、bootsnapがインストールされていないということは考えにくかった。

Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',      '6.1.1'
gem 'puma',       '4.3.6'
gem 'sass-rails', '5.1.0'
gem 'webpacker',  '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder',   '2.9.1'
gem 'bootsnap',   '1.4.5', require: false

group :development, :test do
  gem 'sqlite3', '1.4.1'
  gem 'byebug',  '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',           '4.0.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.1.0'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'capybara',                 '3.28.0'
  gem 'selenium-webdriver',       '3.142.4'
  gem 'webdrivers',               '4.1.2'
  gem 'rails-controller-testing', '1.0.4'
  gem 'minitest',                 '5.14.3'
  gem 'minitest-reporters',       '1.3.8'
  gem 'guard',                    '2.16.2'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
  gem 'pg', '1.1.4'
end

# Windows ではタイムゾーン情報用の tzinfo-data gem を含める必要があります
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

3.試したがうまく行かなかったこと

あまりそうすべきではないだろうと思いつつboot.rbのbootsnap/setupに関わる行をコメントアウトしたが、

boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require "bundler/setup" # Set up gems listed in the Gemfile.
#require "bootsnap/setup" # Speed up boot time by caching expensive operations.

今度はrakeがロードできないと怒られてしまう。

ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
/tmp/build_187f57ec/bin/rake:4:in `require': cannot load such file -- rake (LoadError)

そのままにしとくとまずそうなのでひとまずboot.rbのコメントアウトは解除した。

4.解決した方法

調べている内にこのページにたどり着く。
https://teratail.com/questions/317714

herokuではbundlerが2.1.4までのバージョンのものしか使えないという内容だった。
Gemfile.lockを確認すると確かに対応していないバージョンを使っているようだった。

Gemfile.lock
BUNDLED WITH
   2.2.7

bundler2.1.4をインストールし、Gemfile.lockを一度削除してからそちらを使うように切り替えたら、デプロイに成功した。

$ rm Gemfile.lock 
$ gem install bundler -v 2.1.4
$ bundle _2.1.4_ install --without production

5.更新履歴

2021/04/04:ごく稀にLGTMされるので最初に結論を書いた。

参考

git push heroku master で`require': cannot load such file -- bootsnap/setup (LoadError)
https://teratail.com/questions/317714

6
0
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
6
0