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

时间:2016-04-04 03:51:46

标签: ruby-on-rails heroku

我正在尝试部署一个基本的应用程序,但它无法运行。使用

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"

好吧,我不明白为什么会这样,因为我有另一个正常工作的项目。我检查了一切,它仍然给了我那个消息。

16 个答案:

答案 0 :(得分:7)

有时Heroku会在部署资产方面遇到问题。您可以预编译资产并将其推送到Heroku。

RAILS_ENV=production bundle exec rake assets:precompile

<强>更新

如果它不起作用,请务必添加 RAILS_SERVE_STATIC_FILES env。到了服务器。

将其设为enabledtrueanything:)

因为在Rails&lt; 5.1 production.rb中有

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

  

Heroku:App - &gt;设置 - &gt; “揭示配置变种”

<强>示例: enter image description here

答案 1 :(得分:4)

“资产编译中的任何失败现在都会导致推送失败。对于Rails 5资产管道支持,请参阅Ruby支持页面。”

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

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

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

RAILS_ENV=production bundle exec rake assets:precompile

这应该没有错误。如果按照Heroku的文档使用Rails 3,请不要在运行此命令后将资产签入git。

将创建公共/资产目录。在这个目录中你会找到一个manifest.yml,其中包含Rails 3中已编译资产的md5sums。在Rails 4中,该文件将是manifest-.json。将公共/资产添加到您的git存储库将使其可用于Heroku。

git add public/assets
git commit -m "vendor compiled assets"`

现在推送时,输出应显示已检测到本地编译的资产:

-----> Preparing Rails asset pipeline
   Detected manifest.yml, assuming assets were compiled locally

可以找到更多帮助here

here

答案 2 :(得分:3)

在将 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 的 Bundler 版本是 Bundler 2.2.7,而 Heroku 的 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 版

这次我再次尝试部署它成功了。

仅此而已。

我希望这会有所帮助

答案 3 :(得分:2)

我遇到了同样的问题,事实证明我已经安装了最新的捆绑程序版本(bundler-2.2.1) 您可以通过以下方式检查捆绑程序版本:

  • 捆绑版

Heroku似乎与捆绑程序版本2.1.4兼容。 (不知道为什么) 就我而言,我必须降级到2.1.4版本并将其设置为默认版本。

在我的Ubuntu 20.10中,当我键入:

  • gem卸载捆绑程序

它将卸载捆绑程序版本2.2.1,然后剩下捆绑程序版本2.1.4,然后将其声明为默认的gem,无法卸载,这正是我想要的。所以在那之后我去了我的rails应用程序,

  • 已删除Gemfile.lock
  • 捆绑安装
  • git add。
  • git commit -m“修改后的Gemfile.lock”
  • git push原始主机
  • git push heroku master

一切正常。

答案 4 :(得分:1)

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

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)

最适合我的解决方案来自我在捆绑器上找到的this issue comment。为了进行部署,我必须删除

BUNDLED WITH
   1.17.1

从我的gemfile.lock中,然后使用git push heroku master

答案 5 :(得分:1)

由于该帖子反复出现以寻找我的答案,希望这对某人有帮助。

在将更新部署到已经启动并正在运行的应用程序时,我在Heroku上遇到类似的错误。构建过程没有找到基本命令。这是我的错误消息:

<span th:text=${baseUrl}></span>

捆绑软件,耙子和启动应用程序在本地都可以正常工作。

原来,这是ruby buildpack中更新的问题。我使用以下命令将buildpack版本锁定为旧版本 -----> 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 并重新部署。之后一切都很好。

Heroku堆栈heroku-16和ruby版本2.3.8

答案 6 :(得分:0)

使用rbenv安装ruby 2.6.0

 rbenv install 2.6.0

然后转到您的项目目录并设置ruby版本

 rbenv local 2.6.0

删除安装捆绑包

 gem uninstall bundler

然后安装最新的捆绑软件,以下将安装最新的捆绑软件

 gem install bundler

那你很好。

答案 7 :(得分:0)

您可能还希望将生产中的PG Gem文件添加到gem文件中

GemFile

group :production do
 gem 'pg'
 gem 'rails_12factor'
end

group :development do
 gem 'sqlite3'
end

或:

# 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

答案 8 :(得分:0)

尽管我认为由于我部署应用程序的特殊性质,我可能会收到此错误,但可能会帮助某人。

对我来说

  1. 在推送之前,我没有在生产中设置所需的配置ENV变量。
  2. 我没有设置某些宝石所需的构建包才能工作(Watir等宝石需要)

在heroku上设置了buildpack并设置了生产中所需的ENV变量后,我设法使它起作用。

因此,在将存储库部署到heroku之前,请确保在heroku上导入的所有ENV变量和buildpacks。

答案 9 :(得分:0)

TL; DR; 在您的 Gemfile

的全局范围内拥有gem "better_errors"gem "binding_of_caller"gem 'pry-byebug'

在我的情况下,这是因为我将这3个gem从全局范围移到了我的Gemfile中的development

gem "better_errors"

gem "binding_of_caller"

gem 'pry-byebug'

它们可能应该只在development范围内,但是我缺少一些东西。因此,将它们移回development范围之外,我的部署和耙将正常工作

答案 10 :(得分:0)

对于我来说,错误是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 /

答案 11 :(得分:0)

我都得到了

无法检测到rake任务

LoadError:无法加载此类文件

结果证明我在要求陈述中错了大小写-在Windows(不区分大小写的文件系统)上可以正常工作,但在Heroku上却因这些错误而失败(在查看“无法检测到rake任务”时颇有误导性)< / p>

答案 12 :(得分:0)

不幸的是,这里的答案都没有为我解决问题。我使用 suspenders gem 来设置我的 rails 应用程序。

确保:

APPLICATION_HOST=foobar RAILS_ENV=production be rake assets:precompile

与您的设置配合使用,这样您就可以确保资产编译没有问题。

调整捆绑器版本的建议修复不起作用,因为默认情况下 heroku 现在使用固定的捆绑器版本 (see here)

最后对我来说修复它的是调整我的 rake 文件并将 ruby​​ 版本设置为 2.6.6。更新您的 Gemfile 和您正在使用的任何 ruby​​ 版本管理器。如果您有 .ruby-version 文件,也请更改它。就我而言,我不得不 rbenv install 2.6.6,然后我喜欢在任何地方使用相同的 ruby​​ 版本:rbenv global 2.6.6

以前是这样的:

require "standard/rake"# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
task(:default).clear
task default: [:spec]

if defined? RSpec
  task(:spec).clear
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.verbose = false
  end
end

task default: "bundle:audit"

然后我把它改成了这样:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks

if defined? RSpec
  task(:spec).clear
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.verbose = false
  end
end

task default: "bundle:audit"

然后它就起作用了。希望我能够为你们中的一些人节省我花了 4 个小时修复它的时间。

答案 13 :(得分:0)

我在这个输出中遇到了完全相同的问题:

remote:        Removing bundler (1.17.3)
remote:        Bundle completed (29.91s)
remote:        Cleaning up the bundler cache.
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:  !     /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'spring' (= 2.1.1) among 96 total gem(s) (Gem::MissingSpecError)
remote:  !     Checked in 'GEM_PATH=/tmp/build_49740f40/vendor/bundle/ruby/2.7.0', execute `gem env` for more information
remote:  !     from /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
remote:  !     from /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
remote:  !     from /tmp/build_49740f40/bin/spring:14:in `<top (required)>'
remote:  !     from /tmp/build_49740f40/bin/rake:7:in `load'
remote:  !     from /tmp/build_49740f40/bin/rake:7:in `<main>'
remote:  !
remote: /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)
remote: ensure you can run `$ bundle exec rake -P` against your app

在我的案例中,问题是位于组 :development 中的 gem 'spring' 在 Gemfile 中的生产中丢失,所以我只是从开发中移出并使其在所有环境中都可用。然后我运行 bundle install 并推送到 git 和 Heroku,一切顺利。我刚读完这篇documentation from heroku

答案 14 :(得分:0)

对我来说,这是由 Rakefile 中的标准 gem 引起的(在尝试了其他答案中提到的所有其他修复之后)。

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
# require "standard/rake"

PatchVault::Application.load_tasks

# task default: [:test, "standard:fix"]

在完成第 5 行和第 9 行之后,一切都部署得很好。

Ruby 2.7.2,捆绑器 2.2.6

答案 15 :(得分:0)

这对某人有帮助的可能性很小。 Heroku 输出在错误消息中告诉我自上次成功构建以来对 gemfile 的更改。我认为这极不可能修复错误,但一时兴起我决定尝试一下,希望它不起作用。

#/Gemfile
# I used to have my stripe gem like this 
gem 'stripe', '>= 2.8', '< 6.0'
# The format being like this caused the error
gem 'stripe', '< 6.0', '>= 2.8'

好吧,我现在已经看到了。软件开发的女士们先生们。

相关问题