Heroku推送错误:“无法检测到rake任务”

37

我正在尝试部署一个基本应用程序,但它无法正常工作。使用

git push heroku master 

我收到了这个错误消息:

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:  !     rake aborted!
remote:  !     LoadError: cannot load such file -- /tmp/build_a1cfcabff50107f84830d908386197b2/config/application
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/Rakefile:4:in `require'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/Rakefile:4:in `<top (required)>'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:689:in `raw_load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:94:in `block in load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:93:in `load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:77:in `block in run'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
remote:  !     vendor/bundle/bin/rake:16:in `load'
remote:  !     vendor/bundle/bin/rake:16:in `<main>'
remote:  !
remote: /app/tmp/buildpacks/ruby/lib/language_pack/helpers/rake_runner.rb:102:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)

bundle exec rake -P 看起来正常工作。

我的 Gemfile 中没有什么特别的,我只是添加了 Bootstrap:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'

# 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/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'bootstrap-sass' 
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
#postgreeSQL for Heroku deployment


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'sqlite3'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'


  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end
group :production do
  gem 'pg'
  gem 'rails_12factor'
end
ruby "2.2.3"

好的,我不明白为什么会发生这种情况,因为我有另一个正常运行的项目。我检查了所有内容,但它仍然显示那个消息。


1
如果 bundle update 无效,请确保你正确使用 git:git init -> git add . -> git commit -m "ready for production etc.." -> git push heroku master - Ray
@Raymond,它没有起作用... - jvrn3
它在本地工作吗? - 7urkm3n
1
@jvrn3,你能试着运行这个命令吗?RAILS_ENV=production bundle exec rake assets:precompile - 7urkm3n
@7urkm3n,它起作用了。谢谢! - jvrn3
显示剩余8条评论
22个回答

23

我遇到了同样的问题,后来发现我安装了最新的bundler版本(bundler-2.2.1)。你可以通过以下命令检查你的bundler版本:

  • bundle version

Heroku似乎与bundler版本2.1.4兼容得很好。(不确定原因)。在我的情况下,我不得不降级到版本2.1.4并将其设置为默认版本。

在我的Ubuntu 20.10上,当我输入以下命令时:

  • gem uninstall bundler

它会卸载bundler版本2.2.1,并留下版本2.1.4作为默认gem,而且无法卸载,这正是我想要的结果。所以之后我去了我的rails应用程序,

  • 删除Gemfile.lock
  • bundle install
  • git add .
  • git commit -m "Modified Gemfile.lock"
  • git push origin master
  • git push heroku master

一切都完美地运行了。


4
这里也有同样的问题,使用Rails 6.1,似乎只有降级bundler可行。感谢你的解决方案。 - 15 Volts
你刚刚帮我省了很多麻烦...这真是一个奇怪的情况!再次感谢! - Dennis O'Keeffe
即使在Heroku修复后(来自boyd在其他答案中的文章),这仍然是一个问题,而且这个解决方案仍然有效。谢谢! - cecomp64
这太棒了。 - user15177767
这个可行。我会补充说明,有些情况下需要再次运行bundler和gem rexml。 - Ali Ove

13
有时候Heroku在部署过程中会出现有关资源的问题。您可以预编译资源并将其推送到Heroku。
RAILS_ENV=production bundle exec rake assets:precompile

更新:

如果不起作用,请确保在您的服务器上添加 RAILS_SERVE_STATIC_FILES 环境变量。

将其设置为enabledtrue而不是anything:)

因为在Rails <5.1中,production.rb 有以下配置:

config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

Heroku: 应用程序 -> 设置 -> "显示配置变量"

示例: enter image description here


5
能否解释一下为什么这个方法有效?在得到解释之前,我无法点赞你的回答,而且实话说,很少有人会点赞只提供代码而不解释问题的回答。SO上的回答应该帮助人们理解问题,而不仅仅是提供一行代码。 - jasonleonhard
3
RAILS_ENV=production bundle exec rake assets:precompile这个对我来说不起作用。实际上什么都不起作用。我还能尝试什么别的吗? - dave
1
@dave你的问题是什么? - 7urkm3n
无法检测到Rake任务,请确保您可以针对应用程序运行“$ bundle exec rake -P”,并使用Gemfile的生产组。当我将应用程序推送到Heroku时,出现了中止的 Rake 错误! - dave
2
我在本地运行了"RAILS_ENV=production bundle exec rake assets:precompile",然后将应用程序推送到Heroku,但仍然发生了同样的事情。 - dave
@dave 可能需要打开一个新页面。 - 7urkm3n

9

2020年1月更新:Heroku已于去年12月删除bundler版本,以防止发生这些问题。他们在本文中提到了这一点。

原始帖子:

当我尝试解决相同的错误时,我采取了所有这些步骤:

remote: -----> Installing node-v10.15.3-linux-x64
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:  !     Activating bundler (2.0.1) failed:
remote:  !     Could not find 'bundler' (2.0.1) required by your /tmp/build_2e6c96ff8cd3ab115ee56c51d05c7a28/Gemfile.lock.
remote:  !     To update to the latest version installed on your system, run `bundle update --bundler`.
remote:  !     To install the missing version, run `gem install bundler:2.0.1`
remote:  !     Checked in 'GEM_PATH=/tmp/build_2e6c96ff8cd3ab115ee56c51d05c7a28/vendor/bundle/ruby/2.6.0', execute `gem env` for more information
remote:  !     
remote:  !     To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
remote:  !
remote: /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)

在尝试相同方式部署时出现问题。我遵循了在错误消息中提供的生产环境所有命令,但仍然无法解决。我的版本信息:

~/movie_list [master] $ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
~/movie_list [master] $ bundler version
Bundler version 2.0.1 (2019-01-04 commit d7ad2192f)

我的解决方案最终来自于我在bundler上发现的这个问题评论。为了部署,我必须删除


BUNDLED WITH
   1.17.1

从我的Gemfile.lock文件中获取,然后使用git push heroku master命令推送到Heroku。

7
我很愁这个问题,因为我在将一个Rails 6应用部署到Heroku时遇到了麻烦。
当我尝试部署此应用程序时,出现了以下错误:
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_3d8b676c/bin/rake:8:in `require': cannot load such file -- rake (LoadError)
remote:  !     from /tmp/build_3d8b676c/bin/rake:8:in `<main>'

我尝试但未成功的方法:

  • 删除我的 Gemfile.lock 文件,运行 bundle install 命令,提交到远程的 master 分支,然后推送到 Heroku。
  • 运行 RAILS_ENV=production bundle exec rake assets:precompile 命令,提交到远程的 master 分支,然后推送到 Heroku。
  • Gemfile.lock 文件中移除 Bundler 的版本信息,提交到远程的 master 分支,然后推送到 Heroku。

以下是我解决问题的方法:

对我而言,问题出在项目的 Bundler 版本与 Heroku 的版本不一致。我的 Project's Bundler 版本是 Bundler 2.2.7,而 Heroku's Bundler 版本是 Bundler 2.1.4

通过查看 Heroku 的构建日志,我发现 Heroku 正在使用的 Bundler 版本是 Bundler 2.1.4

promisepreston@my-pc:~/Projects/my-project$ git push heroku develop:master
Enumerating objects: 193, done.
Counting objects: 100% (193/193), done.
Delta compression using up to 8 threads
Compressing objects: 100% (154/154), done.
Writing objects: 100% (155/155), 37.90 KiB | 3.45 MiB/s, done.
Total 155 (delta 105), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.1.4
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.7.2
remote: -----> Installing dependencies using bundler 2.1.4
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4

接下来,我卸载了我的项目的Bundler版本2.2.7,剩下的是默认版本,即Bundler版本2.1.4
这次重试部署成功了。
就这些了。 希望这有所帮助。

5
非常感谢!那很有效!如果有人想知道如何回退到旧版本的bundler,可以按照以下步骤进行操作:先执行 gem uninstall bundler,然后删除 Gemfile.lock 文件,再执行 gem install bundler --version '2.1.4' ,最后再次运行bundle,预编译资产并推送到Heroku。 - Bergrebell
3
“@PeterPiper -小错误:'gem uninstall bundler'” - xivusr
谢谢,问题已经解决了。除此之外,我不明白为什么在使用 bundler 2.2.11 时它会失败,而我的先前的应用程序在该版本下部署正常。同样的平台(DigitalOcean),几乎相同的配置,只是相隔几个月而已。 - a.fahmiin

6

"现在,任何资产编译失败都会导致推送失败。有关Rails 5资产管道支持,请参阅Ruby支持页面。"

Rails资产管道提供了一个assets:precompile rake任务,允许资产在应用程序启动时被预先编译和缓存,而不是每次编译。 在Heroku上,您有两种使用资产管道的方法。 本地编译资产。 在编译时编译资产。

要在本地编译您的资产,请在应用程序上本地运行assets:precompile任务。确保使用生产环境,以生成生产版本的资产。

在Heroku上编译您的资产之前,您需要能够在本地编译它们,请运行此命令调试您的资产:

RAILS_ENV=production bundle exec rake assets:precompile

这个命令应该能够顺利完成,但是如果使用Rails 3请不要将资产文件提交到git中,这是由于Heroku的文档规定。命令执行后会创建一个public/assets目录,在里面你会找到一个manifest.yml文件,其中包含了Rails 3编译资产的md5sums。在Rails 4中,该文件将是manifest-.json。将public/assets目录添加到你的git仓库中,就可以在Heroku上使用了。
git add public/assets
git commit -m "vendor compiled assets"`

现在进行推送时,输出应该显示检测到了您本地编译的资源:
-----> Preparing Rails asset pipeline
   Detected manifest.yml, assuming assets were compiled locally

您可以在这里找到更多帮助。

以及在这里


我已经按照上述步骤操作,但仍然出现相同的错误。 - stevec

2
使用 rbenv 安装 Ruby 2.6.0
 rbenv install 2.6.0

然后进入您的项目目录并设置 Ruby 版本

 rbenv local 2.6.0

移除安装程序包

 gem uninstall bundler

然后安装最新的bundler,以下命令将安装最新的bundler

 gem install bundler

那么你就可以开始了。


1
非常感谢您的回答。一如既往,最好的答案在页面底部 :) - tronerta

2

由于这篇帖子一直在寻找我的答案,希望这能帮助到某些人:

在 Heroku 上部署已经运行的应用程序时,我遇到了类似的错误。构建过程找不到基本命令。这是我的错误消息:

-----> Installing node-v12.16.2-linux-x64
-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     /tmp/build_a61ee567/bin/rake: line 1: require_relative: command not found
 !     /tmp/build_a61ee567/bin/rake: line 2: require: command not found
 !     /tmp/build_a61ee567/bin/rake: line 3: Rake.application.run: command not found
 !
/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)
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
/tmp/build_a61ee567/bin/rake: line 1: require_relative: command not found
/tmp/build_a61ee567/bin/rake: line 2: require: command not found
/tmp/build_a61ee567/bin/rake: line 3: Rake.application.run: command not found
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1068:in `rake'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:84:in `block (2 levels) in run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:78:in `block in run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:77:in `run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:112:in `block (2 levels) in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1089:in `allow_git'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:105:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:94:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:62:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:60:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:42:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:41:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:41:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:40:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:20:in `block (2 levels) in <main>'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:19:in `block in <main>'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `block in trace'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `trace'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:15:in `<main>'
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

捆绑包、扫帚和启动应用程序在本地都很好用。

事实证明,这是由于Ruby构建包中的更新问题。我使用命令heroku buildpacks:set https://github.com/heroku/heroku-buildpack-ruby#v215 -a appname将构建包版本锁定为旧版本,并重新部署。之后一切正常。

Heroku堆栈为heroku-16,Ruby版本为2.3.8。


哇,它真的有用!谢谢! - msayen

1
你可能还想在生产环境的Gem文件中添加PG Gem文件。 Gem文件
group :production do
 gem 'pg'
 gem 'rails_12factor'
end

group :development do
 gem 'sqlite3'
end

OR:

# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]

gem 'rails_12factor', group: :production
gem 'pg', group: :production

一旦您添加了那个,保存并运行以下内容:
终端
gem install bundler
bundle install
git add .
git commit -m "Some comment here..."
git push heroku master

1

我曾经遇到过这个问题,虽然我使用的是Ruby,但没有使用Rails,所以运行rake任务的解决方案是将rake gem添加到Gemfile中。

# Gemfile

...

gem "rake", "~> 13.0"

希望这对未来的其他人有所帮助!


1
在我的情况下,错误是 bin/rake 文件。
    # frozen_string_literal: true
    #!/usr/bin/env ruby
    
    require_relative '../config/boot'
    require 'rake'
    
    Rake.application.run

Heroku要求在顶部加上#!/usr/bin/env ruby,像这样:

    #!/usr/bin/env ruby
    # frozen_string_literal: true

    require_relative '../config/boot'
    require 'rake'
    
    Rake.application.run

解决了! o/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接