jvr*_*rn3 19 ruby-on-rails heroku
我正在尝试部署一个基本的应用程序,但它无法正常工作.运用
git push heroku master
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
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)
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
好吧,我不明白为什么会这样,因为我有另一个正常工作的项目.我检查了一切,它仍然给了我那个消息.
小智 21
我遇到了同样的问题,结果我安装了最新的捆绑程序版本 (bundler-2.2.1) 您可以通过以下方式检查捆绑程序版本:
Heroku 似乎与 bundler 版本 2.1.4 配合得很好。(不知道为什么)在我的情况下,我不得不降级到版本 2.1.4 并将其设为默认版本。
在我的 Ubuntu 20.10 中,当我输入:
它卸载了 bundler 版本 2.2.1,我留下了 bundler 版本 2.1.4,然后它被声明为默认 gem 并且无法卸载,这正是我想要的。所以在那之后我去了我的rails应用程序,
一切都完美无缺。
有时Heroku会在部署资产方面遇到问题.您可以预编译资产并将其推送到Heroku.
RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
更新:
如果它不起作用,请确保添加
RAILS_SERVE_STATIC_FILESenv.到你的服务器.
做它enabled或true不anything:)
因为在Rails <5.1 production.rb中
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Heroku:App - > Settings - >"Reveal Config Vars"
在将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>'
Run Code Online (Sandbox Code Playgroud)
我尝试过但不起作用的事情:
Gemfile.lock,运行bundle install,提交到远程master分支,然后推送到heroku。RAILS_ENV=production bundle exec rake assets:precompile,提交到远程master分支,然后推送到heroku。Gemfile.lock,提交到远程master分支,然后推送到 heroku。这是我修复的方法:
对我来说,问题是由于我的项目的Bundler版本与Heroku的版本不同引起的。我的项目的 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
Run Code Online (Sandbox Code Playgroud)
接下来,我卸载了 My 项目的Bundler version 2.2.7,留下了默认版本,即Bundler version 2.1.4。
这次我再次尝试部署,成功了。
就这样。
我希望这有帮助
Rails资产管道提供了asset:precompile rake任务,以允许资产被编译并预先缓存,而不是每次应用程序启动时都进行编译。您可以使用两种方法在Heroku上使用资产管道。在本地编译资产。在段编译期间编译资产。
要在本地编译资产,请在您的应用上本地运行asset:precompile任务。确保使用生产环境,以便生成资产的生产版本。
RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
这应该没有错误地完成。如果根据Heroku的文档使用Rails 3,请在运行此命令后不要将资产检入git。
将创建一个public / assets目录。在此目录中,您将找到一个manifest.yml,其中包含Rails 3中已编译资产的md5sum。在Rails 4中,文件将为manifest-.json。将公共/资产添加到您的git存储库将使其可用于Heroku。
git add public/assets
git commit -m "vendor compiled assets"`
Run Code Online (Sandbox Code Playgroud)
现在,在推送时,输出应显示检测到本地编译的资产:
-----> Preparing Rails asset pipeline
Detected manifest.yml, assuming assets were compiled locally
Run Code Online (Sandbox Code Playgroud)
在这里可以找到更多帮助
而在这里
当尝试解决相同的错误时,我采取了所有这些步骤:
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)
Run Code Online (Sandbox Code Playgroud)
尝试以相同方式部署时发生了这种情况。我在生产环境中遵循了错误消息提供的所有命令,但仍然无法解决问题。我的版本:
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)
Run Code Online (Sandbox Code Playgroud)
最终对我有用的解决方案来自我在捆绑器上找到的此问题注释。为了部署,我不得不删除
BUNDLED WITH
1.17.1
Run Code Online (Sandbox Code Playgroud)
从我的gemfile.lock中,然后使用git push heroku master。
| 归档时间: |
|
| 查看次数: |
7581 次 |
| 最近记录: |