简体   繁体   中英

Heroku, bundler fails on missing dependencies

I have had trouble recently trying to deploy my rails app on Heroku. In the past, I had deployed apps on Heroku with no problem, but Heroku does not support ruby 2.0.0 anymore. They suggest adding ruby "2.2.4" to the Gemfile , which is what I did. The beginning of my Gemfile is as follows:

source 'https://rubygems.org'
ruby "2.2.4"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use pg as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
...

So, I have run bundle install with version 1.7.8 on my computer with no problem. I can even run my app in production mode. However, when I try to deploy the app on Heroku, I get this:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.2.4
-----> Installing dependencies using bundler 1.11.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching gem metadata from https://rubygems.org/...........
       Fetching version metadata from https://rubygems.org/...
       Fetching dependency metadata from https://rubygems.org/..
       Using rake 10.4.2
       Installing i18n 0.7.0
       Installing minitest 5.4.3
       Installing json 1.8.3 with native extensions
       Installing thread_safe 0.3.4
       Installing builder 3.2.2
       Installing erubis 2.7.0
       Your Gemfile.lock is corrupt. The following gem is missing from the DEPENDENCIES
       section: 'mini_portile2'
       Bundler Output: Fetching gem metadata from https://rubygems.org/...........
       Fetching version metadata from https://rubygems.org/...
       Fetching dependency metadata from https://rubygems.org/..
       Using rake 10.4.2
       Installing i18n 0.7.0
       Installing minitest 5.4.3
       Installing json 1.8.3 with native extensions
       Installing thread_safe 0.3.4
       Installing builder 3.2.2
       Installing erubis 2.7.0
       Your Gemfile.lock is corrupt. The following gem is missing from the DEPENDENCIES
       section: 'mini_portile2'
 !
 !     Failed to install gems via Bundler.
 !
 !     Push rejected, failed to compile Ruby app

Any help is greatly appreciated.

我建议删除您的 Gemfile.lock,在本地再次运行bundle install ,将新的 Gemfile.lock 提交到您的 git 存储库,然后再次尝试您的git push heroku master

I had the same problem and what I did was I updated Ruby 2.2.4 in my system and restarted terminal, then followed these steps:

bundle install
bundle update 
git push heroku

( it's a good idea to update the gems with bundle update to make sure the versions match)

The problem is that you only changed the Ruby version number in the Gemfile , but did not recreate a valid Gemfile.lock . This leads to a Gemfile.lock that contains Gems in versions that are not compatible with Ruby 2.2.4.

If you change something in the Gemfile then you have to update or recreate the Gemfile.lock with the same Ruby version before pushing to Heroku.

I suggest to use a Ruby version manager (like rbenv or RVM ) to be able to run multiple versions of Ruby on your development machine. Then update the Ruby version in your application by changing the Ruby version in Gemfile (for Heroku) and .ruby-version (for your local environment). Both version must match.

Once that is done, run bundle install to update the Gemfile.lock or (when there were major updates or you just want to ensure that you use the latest versions) run bundle update to recreate the Gemfile.lock .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM