Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

ruby on rails - Failed to deploy rails6 app to heroku due to "Can't detect rake task"

What I want to do and what happened

I made a rails app on local. And I want to deploy it to heroku.

I tried this:

$ git push heroku master

But I got error messages like below:

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_646360fd/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 111 total gem(s) (Gem::MissingSpecError)
remote:  !     Checked in 'GEM_PATH=/tmp/build_646360fd/vendor/bundle/ruby/2.7.0', execute `gem env` for more information
remote:  !     from /tmp/build_646360fd/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
remote:  !     from /tmp/build_646360fd/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
remote:  !     from /tmp/build_646360fd/bin/spring:14:in `<top (required)>'
remote:  !     from /tmp/build_646360fd/bin/rake:2:in `load'
remote:  !     from /tmp/build_646360fd/bin/rake:2:in `<main>'
remote:  !

What I tried to resolve

First, I just tried $ bundle exec rake -P as the messages indicated.

And I got this long output:

rake about
    environment
rake action_mailbox:ingress:environment
rake action_mailbox:ingress:exim
    action_mailbox:ingress:environment
rake action_mailbox:ingress:postfix
    action_mailbox:ingress:environment
rake action_mailbox:ingress:qmail
    action_mailbox:ingress:environment
rake action_mailbox:install
rake action_mailbox:install:migrations
rake action_text:install
rake action_text:install:migrations
rake active_storage:install
    environment
rake active_storage:install:migrations
rake active_storage:update
    environment
rake app:binstub:yarn
rake app:template
    environment
rake app:templates:copy
rake app:update
    update:configs
    update:bin
    update:active_storage
    update:upgrade_guide_info
rake app:update:active_storage
rake app:update:bin
rake app:update:configs
rake app:update:upgrade_guide_info
rake assets:clean
    environment
rake assets:clobber
    environment
rake assets:environment
rake assets:precompile
    environment
    yarn:install
rake cache_digests:dependencies
    environment
rake cache_digests:nested_dependencies
    environment
rake db:_dump
rake db:abort_if_pending_migrations
    load_config
rake db:charset
    load_config
rake db:check_protected_environments
    load_config
rake db:collation
    load_config
rake db:create
    load_config
rake db:create:all
    load_config
rake db:drop
    load_config
    check_protected_environments
rake db:drop:_unsafe
    load_config
rake db:drop:all
    load_config
    check_protected_environments
rake db:environment:set
    load_config
rake db:fixtures:identify
    load_config
rake db:fixtures:load
    load_config
rake db:forward
    load_config
rake db:load_config
    environment
rake db:migrate
    load_config
rake db:migrate:down
    load_config
rake db:migrate:redo
    load_config
rake db:migrate:reset
    db:drop
    db:create
    db:migrate
rake db:migrate:status
    load_config
rake db:migrate:up
    load_config
rake db:prepare
    load_config
rake db:purge
    load_config
    check_protected_environments
rake db:purge:all
    load_config
    check_protected_environments
rake db:reset
    db:drop
    db:setup
rake db:rollback
    load_config
rake db:schema:cache:clear
    load_config
rake db:schema:cache:dump
    load_config
rake db:schema:dump
    load_config
rake db:schema:load
    load_config
    check_protected_environments
rake db:schema:load_if_ruby
    db:create
    environment
rake db:seed
    load_config
rake db:seed:replant
    load_config
    truncate_all
    seed
rake db:setup
    db:create
    environment
    db:schema:load
    seed
rake db:structure:dump
    load_config
rake db:structure:load
    load_config
    check_protected_environments
rake db:structure:load_if_sql
    db:create
    environment
rake db:test:load
    db:test:purge
rake db:test:load_schema
    db:test:purge
rake db:test:load_structure
    db:test:purge
rake db:test:prepare
    load_config
rake db:test:purge
    load_config
    check_protected_environments
rake db:truncate_all
    load_config
    check_protected_environments
rake db:version
    load_config
rake default
    spec
rake environment
rake log:clear
rake middleware
    environment
rake railties:install:migrations
    db:load_config
rake restart
rake secret
rake spec
    spec:prepare
rake spec:models
    spec:prepare
rake spec:prepare
rake spec:requests
    spec:prepare
rake spec:statsetup
rake stats
    spec:statsetup
rake test
rake test:all
    test:prepare
rake test:channels
    test:prepare
rake test:controllers
    test:prepare
rake test:db
    db:test:prepare
    test
rake test:functionals
    test:prepare
rake test:generators
    test:prepare
rake test:helpers
    test:prepare
rake test:integration
    test:prepare
rake test:jobs
    test:prepare
rake test:mailboxes
    test:prepare
rake test:mailers
    test:prepare
rake test:models
    test:prepare
rake test:prepare
rake test:run
    test
rake test:system
    test:prepare
rake test:units
    test:prepare
rake time:zones
rake time:zones:all
rake time:zones:local
rake time:zones:us
rake tmp
rake tmp/cache
rake tmp/cache/assets
rake tmp/pids
rake tmp/sockets
rake tmp:cache:clear
rake tmp:clear
    tmp:cache:clear
    tmp:sockets:clear
    tmp:screenshots:clear
rake tmp:create
    tmp/cache
    tmp/sockets
    tmp/pids
    tmp/cache/assets
rake tmp:pids:clear
rake tmp:screenshots:clear
rake tmp:sockets:clear
rake webdrivers:chromedriver:remove
rake webdrivers:chromedriver:update
rake webdrivers:chromedriver:version
rake webdrivers:edgedriver:remove
rake webdrivers:edgedriver:update
rake webdrivers:edgedriver:version
rake webdrivers:geckodriver:remove
rake webdrivers:geckodriver:update
rake webdrivers:geckodriver:version
rake webdrivers:iedriver:remove
rake webdrivers:iedriver:update
rake webdrivers:iedriver:version
rake webpacker
rake webpacker:binstubs
    check_node
    check_yarn
rake webpacker:check_binstubs
rake webpacker:check_node
rake webpacker:check_yarn
rake webpacker:clean
    webpacker:verify_install
    environment
rake webpacker:clobber
    webpacker:verify_install
    environment
rake webpacker:compile
    webpacker:verify_install
    environment
rake webpacker:info
rake webpacker:install
    check_node
    check_yarn
rake webpacker:install:angular
    webpacker:verify_install
rake webpacker:install:coffee
    webpacker:verify_install
rake webpacker:install:elm
    webpacker:verify_install
rake webpacker:install:erb
    webpacker:verify_install
rake webpacker:install:react
    webpacker:verify_install
rake webpacker:install:stimulus
    webpacker:verify_install
rake webpacker:install:svelte
    webpacker:verify_install
rake webpacker:install:typescript
    webpacker:verify_install
rake webpacker:install:vue
    webpacker:verify_install
rake webpacker:verify_install
    check_node
    check_yarn
    check_binstubs
rake webpacker:yarn_install
rake yarn:install
rake zeitwerk:check
    environment

Gemfile is like this:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.2'

gem 'rails', '~> 6.1.0'
gem 'puma', '~> 5.0'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.4', require: false
gem 'devise'

group :development, :test do
  gem 'sqlite3', '~> 1.4'
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
  gem 'factory_bot_rails'
end

group :development do
  gem 'web-console', '>= 4.1.0'
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  gem 'spring'
  gem 'spring-commands-rspec'
end

group :test do
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end

group :production do
  gem 'pg'
end

I modified a config for assets compile in config/environments/production.rb

And database.yml is here:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  << *default
  database: db/development.sqlite3

test:
  << *default
  database: db/test.sqlite3

production:
  << *default
  adapter: postgresql
  encoding: unicode
  pool: 5

I've already create heroku app and add git remote. And I did bundle install and push to heroku.

$ bundle install --without production
$ git add .
$ git commit -m "ready for deploying"
$ git push heroku master

Then I got that errors.

I also tried to create new rails app with the same ruby, bundler and rails version. And modified same things. And then, it worked well.

Sorry for my bad English. Please help me. I will add some codes if you need. Thank you.

Environments

  • ruby 2.7.2p137 (rbenv)
  • rails 6.1.0
  • bundler 2.1.4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same issue today. All I did to solve it was to move the spring gem from the development group to the "main" group in my Gemfile.

Gemfile before:

ruby '2.7.2'

group :development do
  gem 'spring'
end

Gemfile before:

ruby '2.7.2'

gem 'spring'

I hope it also works for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...