Gem::Loaderror: When Trying to Deploy on Heroku - Rails 4

Gem::LoadError: when trying to deploy on Heroku - Rails 4

SQLite is not intended as a production grade database. Instead Heroku provides production grade PostgreSQL databases as a service.

Read the details SQLite on Heroku

Heroku with rails 5 error Gem::LoadError: Specified 'postgresql' for database adapter

If you have recently deployed your app to Heroku and in your attempt have been getting the "App crashed" error when you go to the Heroku app link, but everything else seems to be in order, it's most likely due to a new release of the 'pg' gem. Postgres has released a new version of its gem which seems not fully compatible yet, so in your Gemfile under group production change the line:

gem 'pg'
OR
gem 'pg', '~> 1.0.0'

to

gem 'pg', '~> 0.11'
OR
gem 'pg', '~> 0.20.0'

Note: the tilde sign before the >, that's not a dash

Once you make this update in your group production of your Gemfile, ensure you run bundle install --without production (to update Gemfile.lock file), do a git add/commit cycle, then re-deploy to Heroku.

For Good Practice

Use pg gem one time without :group because your database is same for both development & production!

Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE

Try to write pg outside production, bundle, commit ur code with gemlock,gemfile and push code to heroku then try again

Heroku Rails deployment successful but Application Error

Happy to announce that I was finally able to get this working! The problem was found by running: heroku logs -- appname

I needed to put haml in my production.rb file, and a few other tricky things were missing. Thanks a bunch!

failed to deploy rails app to heroku

It looks like you have mentioned sqlite as database adapter for production. If this is the case, you have to change it to postgresql. In config/database.yml, change the adapter from

default: &default
adapter: sqlite3

to

default: &default
adapter: postgresql

Hope this helps.

Heroku build error: Specified 'sqlite3' for database adapter, but the gem is not loaded

SQLite does not work with Heroku as its disk based and Heroku uses an ephemeral file system.

SQLite runs in memory, and backs up its data store in files on disk.
While this strategy works well for development, Heroku’s Cedar stack
has an ephemeral filesystem. You can write to it, and you can read
from it, but the contents will be cleared periodically. If you were to
use SQLite on Heroku, you would lose your entire database at least
once every 24 hours.

Even if Heroku’s disks were persistent running SQLite would still not
be a good fit. Since SQLite does not run as a service, each dyno would
run a separate running copy. Each of these copies need their own disk
backed store. This would mean that each dyno powering your app would
have a different set of data since the disks are not synchronized.

-Heroku Devcenter: SQLite on Heroku

Heroku provides Postgres as the free default database for rails which is as close to a recommendation as you can get.

If you are deploying to Postgres you should also be developing/testing on Postgres.

Differences between backing services mean that tiny incompatibilities
crop up, causing code that worked and passed tests in development or
staging to fail in production. These types of errors create friction
that disincentivizes continuous deployment. The cost of this friction
and the subsequent dampening of continuous deployment is extremely
high when considered in aggregate over the lifetime of an application.

  • https://12factor.net/dev-prod-parity

If you really want to stick with SQLite you need to configure the adapters properly:

default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3

test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
adapter: postgresql
# nothing else is needed

I do not recommend this.

Heroku deployment - cannot load such file -- rake (LoadError)

[I've edited this original response to include a solution]

I have this exact issue too, with an open ticket with Heroku. No response yet, sadly but I found an answer elsewhere via a lucky hit in Google.

Context, for future reference and search engines

remote: -----> Detecting rake tasks
remote:
remote: !
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_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: ! from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
remote: !
remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: from /tmp/build_b8f358ab/bin/rake:3:in `<main>'

As you've doubtless already found, the suggested bundle exec rake -P command above works fine with any Rails.env setting locally. I, too, tried adding rake to Gemfile explicitly but this made no difference, nor did precompiling assets. Other things to note:

  • All gems build successfully
  • This deploy would prompt and update from Heroku-18 to the Heroku-20 platform; does yours?
  • Rails 5 latest patch, but not Rails 6 yet
  • Ruby 2.7.2

I don't use Spring so my bin/rake is simpler:

#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

...and as with your more complex code, it's definitely the require 'rake' that fails.

Solution

I can't take credit - it's this answer:

  • https://stackoverflow.com/a/65604896

...that solved it, only you need to change from 2.1.2 to 2.1.4. Copy-pasting the above solution - again this is not my work, the credit belongs to the OP above:

gem uninstall bundler
gem install bundler --version '2.1.4' # If this doesn't work - see below

rm Gemfile.lock
bundle install

git add Gemfile.lock
git commit -m "Downgrade Bundler to match current Heroku version, so that deployments succeed"
git push heroku

This has solved the issue in my case. Seems like an utterly bizarre solution, but there you go.

If you don't seem to be unable to downgrade Bundler

In the comments on this answer, the OP notes:

Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem.

$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem

StackOverflow prefer answers to be inline rather than linked externally as external links can break, so once again noting that credit goes to the article linked above:

From all the references I can find, the only way to remove it is to delete the bundler-2.1.4.gemspec file from the gem path. The following commands did the trick for me [...] I wrote a script for you:

#!/usr/bin/env ruby

gempaths = `gem env gempath`.split(":")
gempaths.each do |gempath|
# lookup bundler-*.gemspec files and delete them
# this is the only way to completely cleanup default bundler
# Note: the bundler gemspecs' paths are different for CRuby and JRuby
Dir.glob(gempath.strip + "/specifications/**/bundler-*.gemspec").each { |p| File.delete(p) }
end

# Remember to make this file executable

...so hopefully if you save that as a .rb file somewhere convenient, chmod u+x foo.rb and ./foo.rb - that might solve the problem.



Related Topics



Leave a reply



Submit