Heroku不会识别’spring’gem,即使它已在Gemfile中列出

我过去部署到Heroku只有很少的问题。 今天我创建了一个非常基本的应用程序(字面上只是默认的’new’,带有更新的gemfile)并将其推送到Heroku。

但是,Heroku不会识别’spring’gem,即使它已在Gemfile中列出。 这导致我的应用程序崩溃。 在被问到之前,是的,我在更新Gemfile后运行了bundle installbundle update

Gemfile(从RoR教程中直接复制粘贴):

 source 'https://rubygems.org' gem 'rails', '4.2.2' gem 'sass-rails', '5.0.2' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.1.0' gem 'jquery-rails', '4.0.3' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' gem 'sdoc', '0.4.0', group: :doc group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' end group :test do gem 'minitest-reporters', '1.0.5' gem 'mini_backtrace', '0.1.3' gem 'guard-minitest', '2.3.1' end group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end 

运行heroku run rails console后出现错误信息:

 Running rails console on pure-falls-2221... up, run.6936 /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'spring' (= 1.1.3) among 59 total gem(s) (Gem::LoadError) from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec' from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem' from /app/bin/spring:12:in `' from /app/bin/rails:4:in `load' from /app/bin/rails:4:in `' 

Heroku日志:

 2015-11-17T02:00:32.426615+00:00 heroku[slug-compiler]: Slug compilation started 2015-11-17T02:00:32.426624+00:00 heroku[slug-compiler]: Slug compilation finished 2015-11-17T02:00:35.179885+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 29889 -e production` 2015-11-17T02:00:37.945522+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec' 2015-11-17T02:00:37.945526+00:00 app[web.1]: from bin/rails:4:in `' 2015-11-17T02:00:37.945524+00:00 app[web.1]: from /app/bin/spring:12:in `' 2015-11-17T02:00:37.945525+00:00 app[web.1]: from bin/rails:4:in `load' 2015-11-17T02:00:37.945523+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem' 2015-11-17T02:00:37.945512+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'spring' (= 1.1.3) among 59 total gem(s) (Gem::LoadError) 2015-11-17T02:00:38.782080+00:00 heroku[web.1]: Process exited with status 1 2015-11-17T02:00:40.980407+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 7751 -e production` 2015-11-17T02:00:38.801178+00:00 heroku[web.1]: State changed from starting to crashed 2015-11-17T02:00:38.801178+00:00 heroku[web.1]: State changed from crashed to starting 2015-11-17T02:00:43.123615+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'spring' (= 1.1.3) among 59 total gem(s) (Gem::LoadError) 2015-11-17T02:00:43.123626+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec' 2015-11-17T02:00:43.123629+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem' 2015-11-17T02:00:43.123630+00:00 app[web.1]: from /app/bin/spring:12:in `' 2015-11-17T02:00:43.123630+00:00 app[web.1]: from bin/rails:4:in `load' 2015-11-17T02:00:43.123631+00:00 app[web.1]: from bin/rails:4:in `' 2015-11-17T02:00:44.203452+00:00 heroku[web.1]: State changed from starting to crashed 2015-11-17T02:01:05.291898+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pure-falls-2221.herokuapp.com request_id=adc1ccb9-cd90-45fd-b179-ef680f936c2f fwd="125.140.58.57" dyno= connect= service= status=503 bytes= 2015-11-17T02:01:06.107852+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=pure-falls-2221.herokuapp.com request_id=a92abeed-9b09-4ff8-b535-bac178eb454b fwd="125.140.58.57" dyno= connect= service= status=503 bytes= 2015-11-17T02:01:19.376119+00:00 heroku[api]: Starting process with command `rails console` by chrabyrd@gmail.com 2015-11-17T02:01:21.779621+00:00 heroku[run.6936]: Awaiting client 2015-11-17T02:01:21.797009+00:00 heroku[run.6936]: Starting process with command `rails console` 2015-11-17T02:01:22.153107+00:00 heroku[run.6936]: State changed from starting to up 2015-11-17T02:01:24.185437+00:00 heroku[run.6936]: State changed from up to complete 2015-11-17T02:01:24.169704+00:00 heroku[run.6936]: Process exited with status 1 

任何帮助将不胜感激!

您在development组中拥有gem。 如果你把它从那个组中取出并放在主组中,再做一个bundle install ,将它添加到repo并重新部署,我认为它一切正常。

我是Rails的新手并且也在阅读教程。 我有同样的问题。 经过多次观察和与经验丰富的Rails开发人员讨论之后,这是一个答案。

根据您的日志文件查看第4行的bin / rails文件:(这是代码。第4行是发生错误的位置。)

 #!/usr/bin/env ruby begin spring_bin_path = File.expand_path('../spring', __FILE__) load spring_bin_path rescue LoadError => e raise unless e.message.end_with? spring_bin_path, 'spring/binstub' end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' 

如果删除第6行,则不会引发错误,也不会加载弹簧。 这是以前版本的bin / rails代码所做的,并且一切正常。 我不知道它是Rails还是Cloud9或者是什么产生了这个代码但是在过去的几天里发生了一些变化,毫无疑问。

注意:确保将spring gem保留在gemfile的开发组中。 我不会将spring gem移动到gemfile中的主要组,因为不管我的有限知识是什么,Spring都不应该在生产中运行。

希望这可以帮助。

我和spring人一起买了一张票

https://github.com/rails/spring/issues/450

我怀疑这与spring gem发布版本1.4.4有关

在Spring团队提出更好的解决方案之前,我已修补bin/rails并设置Heroku环境变量以避免在生产中加载Spring:

heroku config:set DISABLE_SPRING=1

斌/导轨:

 #!/usr/bin/env ruby unless ENV["DISABLE_SPRING"] begin spring_bin_path = File.expand_path('../spring', __FILE__) load spring_bin_path rescue LoadError => e raise unless e.message.end_with? spring_bin_path, 'spring/binstub' end end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' 

DISABLE_SPRING是根据其文档推荐的环境变量 。

弹簧的最新版本是1.4.2。 您可能希望以该版本而不是旧版本执行spring。