Omanba Forum

How do I solve the error "pre-receive hook declined" when pushing to Heroku?

I am going nuts with the feedback I keep getting anytime I tried to push my simple “hello_app” developed in rails to production (Heroku).

When I run the command $git push -u origin master, my terminal returned this output:

Enumerating objects: 84, done.
Counting objects: 100% (84/84), done.
Delta compression using up to 4 threads
Compressing objects: 100% (70/70), done.
Writing objects: 100% (84/84), 20.10 KiB | 935.00 KiB/s, done.
Total 84 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote:                         Detected buildpacks: Ruby,Node.js
remote:                         See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.3.10
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.0.3
remote:
remote: ###### WARNING:
remote:
remote:        Removing `Gemfile.lock` because it was generated on Windows.
remote:        Bundler will do a full resolve so native gems are handled properly.
remote:        This may result in unexpected gem versions being used in your app.
remote:        In rare occasions Bundler may not be able to resolve your dependencies at all.
remote:
remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: -----> Installing dependencies using bundler 2.3.10
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin bundle install -j4
remote:        Fetching gem metadata from https://rubygems.org/...........
remote:        Resolving dependencies...
remote:        Bundler found conflicting requirements for the Ruby      Ruby
remote:            puma (= 3.9.1) was resolved to 3.9.1, which depends on
remote:              Ruby= 5.1.6) was resolved to 5.1.6, which depends on
remote:              Ruby       Bundler Output: Fetching gem metadata from https://rubygems.org/...........
remote:        Resolving dependencies...
remote:        Bundler found conflicting requirements for the Ruby5) was resolved to 3.1.5, which depends on
remote:              Rubyto 3.9.1, which depends on
remote:              Ruby on
remote:              Ruby compile Ruby app.
remote:
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 516b0e333aa38520d60b08af341333d210469337
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 516b0e333aa38520d60b08af341333d210469337
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to young-tundra-01436.
remote:
To https://git.heroku.com/young-tundra-01436.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/young-tundra-01436.git'

I’ve spent about 4 Days working on this problem but nothing is working.

I am working with Ubuntu using Windows Subsystem for Linux (WSL).
Any help will be greatly appreciated!

Post the content of your Gemfile and Gemfile.lock

Gemfile

source 'https://rubygems.org'

gem 'rails',        '5.1.6'

gem 'puma',         '3.9.1'

gem 'sass-rails',   '5.0.6'

gem 'uglifier',     '3.2.0'

gem 'coffee-rails', '4.2.2'

gem 'jquery-rails', '4.3.1'

gem 'turbolinks',   '5.0.1'

gem 'jbuilder',     '2.7.0'

group :development, :test do

  gem 'sqlite3', '1.3.13'

  gem 'byebug',  '9.0.6', platform: :mri

end

group :development do

  gem 'web-console',           '3.5.1'

  gem 'listen',                '3.1.5'

  gem 'spring',                '2.0.2'

  gem 'spring-watcher-listen', '2.0.1'

end

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

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.1.6)
      actionpack (= 5.1.6)
      nio4r (~> 2.0)
      websocket-driver (~> 0.6.1)
    actionmailer (5.1.6)
      actionpack (= 5.1.6)
      actionview (= 5.1.6)
      activejob (= 5.1.6)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.1.6)
      actionview (= 5.1.6)
      activesupport (= 5.1.6)
      rack (~> 2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.1.6)
      activesupport (= 5.1.6)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (5.1.6)
      activesupport (= 5.1.6)
      globalid (>= 0.3.6)
    activemodel (5.1.6)
      activesupport (= 5.1.6)
    activerecord (5.1.6)
      activemodel (= 5.1.6)
      activesupport (= 5.1.6)
      arel (~> 8.0)
    activesupport (5.1.6)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    arel (8.0.0)
    bindex (0.8.1)
    builder (3.2.4)
    byebug (9.0.6)
    coffee-rails (4.2.2)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.1.10)
    crass (1.0.6)
    erubi (1.10.0)
    execjs (2.8.1)
    ffi (1.15.5)
    ffi (1.15.5-java)
    ffi (1.15.5-x64-mingw32)
    ffi (1.15.5-x86-mingw32)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    i18n (1.12.0)
      concurrent-ruby (~> 1.0)
    jbuilder (2.7.0)
      activesupport (>= 4.2.0)
      multi_json (>= 1.2)
    jquery-rails (4.3.1)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    listen (3.1.5)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
      ruby_dep (~> 1.2)
    loofah (2.18.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    method_source (1.0.0)
    mini_mime (1.1.2)
    mini_portile2 (2.4.0)
    minitest (5.15.0)
    multi_json (1.15.0)
    nio4r (2.5.8)
    nio4r (2.5.8-java)
    nokogiri (1.10.10)
      mini_portile2 (~> 2.4.0)
    nokogiri (1.10.10-java)
    nokogiri (1.10.10-x64-mingw32)
      mini_portile2 (~> 2.4.0)
    nokogiri (1.10.10-x86-mingw32)
      mini_portile2 (~> 2.4.0)
    puma (3.9.1)
    puma (3.9.1-java)
    rack (2.2.4)
    rack-test (2.0.2)
      rack (>= 1.3)
    rails (5.1.6)
      actioncable (= 5.1.6)
      actionmailer (= 5.1.6)
      actionpack (= 5.1.6)
      actionview (= 5.1.6)
      activejob (= 5.1.6)
      activemodel (= 5.1.6)
      activerecord (= 5.1.6)
      activesupport (= 5.1.6)
      bundler (>= 1.3.0)
      railties (= 5.1.6)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.3)
      loofah (~> 2.3)
    railties (5.1.6)
      actionpack (= 5.1.6)
      activesupport (= 5.1.6)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (13.0.6)
    rb-fsevent (0.11.1)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    ruby_dep (1.5.0)
    sass (3.7.4)
      sass-listen (~> 4.0.0)
    sass-listen (4.0.0)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    sass-rails (5.0.6)
      railties (>= 4.0.0, < 6)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    spring (2.0.2)
      activesupport (>= 4.2)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (3.7.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.2)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.13)
    sqlite3 (1.3.13-x64-mingw32)
    sqlite3 (1.3.13-x86-mingw32)
    sqlite3 (1.3.13-x86-mswin32-60)
    thor (1.2.1)
    thread_safe (0.3.6)
    thread_safe (0.3.6-java)
    tilt (2.0.10)
    turbolinks (5.0.1)
      turbolinks-source (~> 5)
    turbolinks-source (5.2.0)
    tzinfo (1.2.9)
      thread_safe (~> 0.1)
    tzinfo-data (1.2022.1)
      tzinfo (>= 1.0.0)
    uglifier (3.2.0)
      execjs (>= 0.3.0, < 3)
    web-console (3.5.1)
      actionview (>= 5.0)
      activemodel (>= 5.0)
      bindex (>= 0.4.0)
      railties (>= 5.0)
    websocket-driver (0.6.5)
      websocket-extensions (>= 0.1.0)
    websocket-driver (0.6.5-java)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)

PLATFORMS
  java
  ruby
  x64-mingw32
  x86-mingw32
  x86-mswin32

DEPENDENCIES
  byebug (= 9.0.6)
  coffee-rails (= 4.2.2)
  jbuilder (= 2.7.0)
  jquery-rails (= 4.3.1)
  listen (= 3.1.5)
  puma (= 3.9.1)
  rails (= 5.1.6)
  sass-rails (= 5.0.6)
  spring (= 2.0.2)
  spring-watcher-listen (= 2.0.1)
  sqlite3 (= 1.3.13)
  turbolinks (= 5.0.1)
  tzinfo-data
  uglifier (= 3.2.0)
  web-console (= 3.5.1)

BUNDLED WITH
   2.0.2

Show what you have when you do ruby -v

ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

Got it. Try this:

  1. Delete your Gemfile.lock
  2. Add ruby "2.4.1" to your Gemfile
  3. Do bundle update --bundler
  4. Run bundle install
  5. Commit the changes, push to Heroku

Let’s see if that fixes it.

Game Show Thank You GIF by Kinda Funny

Ok…I’m on it

This the feedback from running the above commands

Could not find gem 'ruby (= 2.4.1)' in any of the gem sources listed in your Gemfile.

This is the Build Log from Heroku:

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
 !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
			Detected buildpacks: Ruby,Node.js
			See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Ruby app detected
-----> Installing bundler 1.17.3
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.0.3
###### WARNING:
       Removing `Gemfile.lock` because it was generated on Windows.
       Bundler will do a full resolve so native gems are handled properly.
       This may result in unexpected gem versions being used in your app.
       In rare occasions Bundler may not be able to resolve your dependencies at all.
       
       https://devcenter.heroku.com/articles/bundler-windows-gemfile
-----> Installing dependencies using bundler 1.17.3
       Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_GLOBAL_PATH_APPENDS_RUBY_SCOPE=1 bundle install -j4
       Fetching gem metadata from https://rubygems.org/...........
       Resolving dependencies...
       Bundler found conflicting requirements for the Ruby version:
         In Gemfile:
           Ruby
       
           listen (= 3.1.5) was resolved to 3.1.5, which depends on
             Ruby (>= 2.2.3, ~> 2.2)
       
           pg (= 0.20.0) was resolved to 0.20.0, which depends on
             Ruby (>= 2.0.0)
       
           puma (= 3.9.1) was resolved to 3.9.1, which depends on
             Ruby (>= 1.9.3)
       
           rails (= 5.1.6) was resolved to 5.1.6, which depends on
             Ruby (>= 2.2.2)
       Bundler Output: Fetching gem metadata from https://rubygems.org/...........
       Resolving dependencies...
       Bundler found conflicting requirements for the Ruby version:
         In Gemfile:
           Ruby
       
           listen (= 3.1.5) was resolved to 3.1.5, which depends on
             Ruby (>= 2.2.3, ~> 2.2)
       
           pg (= 0.20.0) was resolved to 0.20.0, which depends on
             Ruby (>= 2.0.0)
       
           puma (= 3.9.1) was resolved to 3.9.1, which depends on
             Ruby (>= 1.9.3)
       
           rails (= 5.1.6) was resolved to 5.1.6, which depends on
             Ruby (>= 2.2.2)
 !
 !
 Failed to install gems via Bundler.

!
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

What are you using to manage Ruby versions?

Am using RVM to manage them

OK. Do rvm list and paste your results here

* ruby-2.4.1 [ x86_64 ]

 => - current
 =* - current && default
  * - default

@siaw, this issue is now resolved. I tweaked one or two things here and there and I’ve been able to deploy successfully:

First of all, after running this commands properly,

this error was taken care of

But I got a new one which said :

Precompiling assets failed

so I added this line config.assets.initialize_on_precompile = false to my config/application.rb file

Deployment was successful but I got Application Error on Heroku

What I did next was to upgrade my Ruby version from 2.4.1 to 2.6.8 and this time around, it was successful on all fronts!

Thanks Big Man

1 Like