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

我正在尝试部署一个基本的应用程序,但它不起作用。 运用

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 `' 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 `' remote: ! vendor/bundle/bin/rake:16:in `load' remote: ! vendor/bundle/bin/rake:16:in `' 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  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" 

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

我明白了,你的资产问题。 这个应该帮助你,解决它。

 RAILS_ENV=production bundle exec rake assets:precompile 

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

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

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

在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 

可以在这里找到更多帮助

在这里