Heroku deploy Ruby 2.6.1 : warn_for_outdated_bundler_version - ruby-on-rails

This question is related to this one, but the proposed solutons didn't work for me.
I'm trying to deploy a Rails 5.2 application with Ruby 2.6.1, but I keep getting this error in the deployment phase:
/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:95:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `to_definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:13:in `evaluate'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:34:in `build'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:135:in `definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:101:in `setup'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/config/boot.rb:3:in `<top (required)>'
from /app/bin/rake:2:in `require_relative'
from /app/bin/rake:2:in `<main>'
What I find strange in this error is this line:
/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
Heroku seems to say it is using Ruby 2.6.0. But in the build phase, it says it uses Ruby 2.6.1 with Bundler 2:
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.1
-----> Installing dependencies using bundler 2.0.1
The build is successful, but the deployment is in failure.
Here is how is configured my app.
Gemfile (reduced to what matters)
ruby "2.6.1"
gem 'rails', '~> 5.2'
Gemfile.lock (reduced to what matters)
RUBY VERSION
ruby 2.6.1p33
BUNDLED WITH
2.0.1
On heroku, my buildpack is heroku/ruby. My stack is heroku-18.
Heroku seems to be supporting Bundler 2, as said in this post.
Any idea on what could fail in the deployment?

I found a solution. The problem was at deploy time, not during the build. The deployment was using Ruby 2.6.0, because of Heroku's web dyno that is by default:
rails server -p $PORT -e $RAILS_ENV
Yet, this post from bundler github is telling to prefix every single command with bundle exec. But the rails server command from the dyno is not prefixed so.
A workaround I found is modifying the project Procfile file, and add the following line:
web: bundle exec rails server -p $PORT -e $RAILS_ENV
This way, the rails server command uses the expected Ruby version, the 2.6.1 insteand of the 2.6.0 that generated the error.

Related

Rails deployment on heroku failed. Rails couldn't infer whether you are using multiple databases from your database.yml

I was deploying my Rails application on Heroku and the deploy failed with this error message.
Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.
I have deployed continuously on Heroku for over a year and no major changes were made.
The change involved updating the gemfile from ruby '2.6.3' to ruby '3.1.2'.
Here is the full trace
Building on the Heroku-22 stack
Using buildpacks:
1. heroku/ruby
2. heroku/nodejs
Ruby app detected
Installing bundler 2.3.10
Removing BUNDLED WITH version in the Gemfile.lock
Compiling Ruby/Rails
###### WARNING:
Your app was upgraded to bundler 2.3.10.
Previously you had a successful deploy with bundler 2.2.21.
If you see problems related to the bundler version please refer to:
https://devcenter.heroku.com/articles/bundler-version#known-upgrade-issues
Using Ruby version: ruby-3.1.2
Purging Cache. Changing stack from heroku-18 to heroku-22
Installing dependencies using bundler 2.3.10
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
A bunch of gems fetching and installing
Bundle complete! 22 Gemfile dependencies, 78 gems now installed.
Gems in the groups 'development' and 'test' were not installed.
Bundled gems are installed into `./vendor/bundle`
Post-install message from mailjet:
The Ruby wrapper for Mailjet has just been installed successfully, congrats!
Maybe you want to configure your credentials to use your account.
All informations available on https://github.com/mailjet/mailjet-gem.
But if you are using Rails, you'll be glad to generate it easily using:
$ rails generate mailjet:initializer
We hope you will enjoy Mailjet!
Bundle completed (86.70s)
Cleaning up the bundler cache.
Installing node-v16.13.1-linux-x64
Installing yarn-v1.22.17
Detecting rake tasks
Preparing app for Rails asset pipeline
Running: rake assets:precompile
Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.
rake aborted!
Psych::BadAlias: Unknown alias: default
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:30:in `available_environments'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:21:in `current'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:15:in `inquire'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:7:in `inquire'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/instance.rb:11:in `env'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/instance.rb:18:in `config'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker.rb:34:in `config'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/webpacker-4.3.0/lib/webpacker/railtie.rb:32:in `block in <class:Engine>'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/initializable.rb:32:in `instance_exec'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/initializable.rb:32:in `run'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/initializable.rb:60:in `run_initializers'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/application.rb:363:in `initialize!'
/tmp/build_f6d25fed/config/environment.rb:5:in `<main>'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/activesupport-6.0.5.1/lib/active_support/dependencies.rb:324:in `block in require'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/activesupport-6.0.5.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/activesupport-6.0.5.1/lib/active_support/dependencies.rb:324:in `require'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/application.rb:339:in `require_environment!'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/railties-6.0.5.1/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/tmp/build_f6d25fed/vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.4.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
It was a compatibility issue with the new ruby version, just adding the psych gem fixed this.
gem 'psych', '< 4'

(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) on apple M1 chip when running rake db:create

when I try to create my database this error appear
$ rake db:create
rake aborted!
LoadError: dlopen(/Users/agonzalez/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle, 0x0009): tried: '/Users/agonzalez/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) - /Users/agonzalez/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle
/Users/agonzalez/Documents/join/config/application.rb:7:in `<top (required)>'
/Users/agonzalez/Documents/join/Rakefile:4:in `require_relative'
/Users/agonzalez/Documents/join/Rakefile:4:in `<top (required)>'
Caused by:
LoadError: cannot load such file -- /Users/agonzalez/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/2.7/nokogiri
/Users/agonzalez/Documents/join/config/application.rb:7:in `<top (required)>'
/Users/agonzalez/Documents/join/Rakefile:4:in `require_relative'
/Users/agonzalez/Documents/join/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
I already try
bundle config set force_ruby_platform true
My ruby version is ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [-darwin21]
bundle version 2.1.4
Rails version 5.2.7
Nokogiri version nokogiri-1.13.6
I was having a similar issue, ultimately what fixed it was uninstalling nokogiri and then reinstalling it with specific platform like so:
gem uninstall nokogiri
gem install nokogiri -v 1.13.6 --platform arm64-darwin
This got me up and running for the time being. I suspect it may break again if I ever do a bundle install in the future, there may be a way to fix this via editing the Gemfile but I'm not sure what that would look like.
The above answers have no effect on me.
Following the steps below works for me:
:bundle config --global build.ffi --enable-libffi-alloc
:rm -rf ~/.bundle/vendor

Ubuntu + Unicorn: You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)

I have a problem to run unicorn on Ubuntu 16. When trying to run it - either manually (service unicorn_myapp_staging restart) or through Capistrano, I get this message: You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError) (below is the full error track)
/home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/lockfile_parser.rb:95:in `initialize'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/definition.rb:72:in `new'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/definition.rb:72:in `initialize'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/dsl.rb:200:in `new'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/dsl.rb:200:in `to_definition'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/dsl.rb:12:in `evaluate'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/definition.rb:33:in `build'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler.rb:128:in `definition'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler.rb:94:in `setup'
from /home/deployer/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/setup.rb:20:in `<top (required)>'
from /home/deployer/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/deployer/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
If I check the version of bundler, it seems to be fine:
bundle info bundler
* bundler (2.1.4)
Summary: The best way to manage your application's dependencies
Homepage: https://bundler.io
Path: /home/deployer/.rvm/gems/ruby-2.6.3/gems/bundler-2.1.4
However, as is stated on the error message above, it looks that the used versions of ruby and bundler are old (2.3.3 and 1.14.3) compared to the newly upgraded ruby (2.6.3) and bundler (2.1.4).
Where do I set the correct versions of ruby and bundler for starting Unicorn? Is there a hidden config file on Ubuntu, where I need to specify it?
Try this fix, looks like issue with Gemfile.lock. Try removing BUNDLED WITH from gemfile.lock.
Remove something like and build again
BUNDLED WITH
2.1.4

rails server works but "rails console" not working

I'm working on a rails project. With command "bundle exec rails s" I can fire up a local server, however, "bundle exec rails c" throws the following errors:
/Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:33:in `<module:Spring>'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:4:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:77:in `preload'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:143:in `serve'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Ruby version: 2.2.2
Rails version: 4.2.5
gem version: 2.5.2
Bundler version: 1.11.2
[UPDATE]: it turns out that commenting out "spring" in Gemfile will solve this issue.
Okay, I came across this after having the same problem as poster. His update suggesting that removing spring from the Gemfile helped me get on the right track. The problem for me was that I had introduced a new environment variables, but spring didn't pick it up. When you remove spring from the Gemfile, it prevents your app from using the spring process, but it doesn't actually stop the spring process so adding it back, doing bundle install, or anything else will still leave you with the same spring process running.
To see if this is likely your issue, you can check bin/spring status and see if spring is running in the background, and if it has been running for a while.
Solution (at least for me): restart spring
bin/spring stop
rails c
Have you tried gem update --system? You may need an updated version of rubygems.
if you use rvm set the default ruby version using following, so it will pickup the correct ruby version. you probably needs to run bundle install/gem install rails -v 4.2.5 after setting the default
rvm --default 2.2.2

CentOS release 6.7: bin/rails c staging error: uninitialized constant Bundler(NameError)

Its weird with CentOS release 6.7 (Final) that unable to run console on stage.
Ruby-version => 2.0.0
Rails- version => 4.1
Once I do bin/rails c staging
/var/www/rails/Ixentech/releases/20151201150901/config/application.rb:7:in `<top (required)>': uninitialized constant Bundler (NameError)
from /home/carmatec/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /home/carmatec/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /home/carmatec/.rvm/gems/ruby-2.0.0-p643/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:141:in `require_application_and_environment!'
from /home/carmatec/.rvm/gems/ruby-2.0.0-p643/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:67:in `console'
from /home/carmatec/.rvm/gems/ruby-2.0.0-p643/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/carmatec/.rvm/gems/ruby-2.0.0-p643/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from /home/carmatec/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /home/carmatec/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /home/carmatec/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from bin/rails:4:in `<main>'
as I completely check with
uninitialized-constant-bundler-nameerror
nameerror-uninitialized-constant-bundler
bin dir permission
and
constant-bundler-namee
but no luck !!!
These answer work with ubuntu 12.04 LTS but not with CentOS
release 6.7 (Final) Further, I checked Redmine as well.
Any help would be appreciate !!!
Try gem install bundler from the command line. Then you'll also want to bundle install from the project directory.
It looks like your system doesn't have "bundler" installed on it yet. Bundler is a dependency manager, once it's installed the bundle install command will install any other gems needed by your project (such as rails itself!).
Did you copy this project directory over from another computer, or git clone it there or something? Cause you'd need bundler installed to create a Rails app in the first place, normally.
Bundler isn't actually included with a ruby install, but you need it as the first thing for Rails, and much other modern ruby code. After installing ruby on a new machine (or starting fresh on a new machine that has ruby pre-installed) gem install bundler should always be the next step.

Resources