Could not detect rake tasks

前端 未结 5 950
一生所求
一生所求 2020-12-20 13:07
   ensure you can run `$ bundle exec rake -P` against your app with no environment variables present
   and using the production group of your Gemfile.
   This may b         


        
相关标签:
5条回答
  • 2020-12-20 13:11

    Effective December 05, 2013, Heroku added debug output to deploys using the Ruby build pack.

    The error is triggered:

    • if the assets:precompile task does not exist or
    • if there is an error in the Rakefile.
      • Two common causes of errors in the Rakefile are referencing a dependency not available in production (such as rspec) or
      • expecting an environment variable to be present.

    It's counter-intuitive because the app never runs without config vars, but Heroku's build process executes without config vars.

    As per the error message, ensure you can run bundle exec rake -P RAILS_ENV=production with no environment variables present before pushing to Heroku (e.g. comment out your environment variables while running the aforementioned command).

    Also, rest assured that rake's -P switch is harmless, so you can run it as much as you want until you fix this issue. This switch is used to display a list of all tasks and their immediate prerequisites. See Rake Command Line Usage if you want to double-check. The output may have over 200 lines, and look something like this:

    rake about
        environment
    rake assets:clean
        environment
    rake assets:clobber
        environment
    rake assets:environment
    rake assets:precompile
        environment
    rake db:_dump
    ...
    rake tmp:pids:clear
    rake tmp:sessions:clear
    rake tmp:sockets:clear
    
    0 讨论(0)
  • 2020-12-20 13:19

    Old question, but I ran into this issue just now, and there is a new fix for it. If you're using Ruby version <= 2.6.1, and Bundler 2.0.1, update Ruby to 2.6.3 ($ rvm install "ruby-2.6.3") and Bundler to 2.0.2 ($ gem install bundler '2.0.2'). Make sure to specify the new Ruby version in your Gemfile.

    Unfortunately I can't tell you why this works, but it's worked for 3 other people on my team so far, so it's worth a shot.

    0 讨论(0)
  • 2020-12-20 13:24

    you can also try enabling user-env-compile

    heroku labs:enable user-env-compile
    
    0 讨论(0)
  • 2020-12-20 13:34

    FWIW I just ran into this issue also.

    It turned out that I had config.assets.css_compressor = :sass commented out, when there was a rake task referring to it in production.rb.

    Very simple oversight, but that would cause rake assets:precompile to fail and thus cause this error.

    0 讨论(0)
  • 2020-12-20 13:35

    I started getting this strange error all of a sudden yesterday. Heroku confirmed making an update to the Ruby buildpack...

    It has to do with the Rakefile. Does your Rakefile require any files? Does it require your app files? If so, then the app should not raise exceptions when it is loaded without any config vars set.

    It's counter-intuitive because the app never runs without the config vars set.

    In my case, the Sinatra app was looking for database urls in the init file:

    uri = URI.parse( ENV[ "REDISTOGO_URL" ])
    

    This will raise an exception if there are no env vars set.

    You may have the same issue with other database URL's, such as Mongo or Postgres.

    So, protect against missing env vars:

    if  ENV[ "REDISTOGO_URL" ]
      uri = URI.parse( ENV[ "REDISTOGO_URL" ])
      ...
    

    You can check if it will work before pushing to Heroku by running bundle exec rake -P

    Also, make sure all your tests pass after updating your init. Remove any cached init state by restarting Spork or similar.

    Reference: Show Rakefile errors in Ruby deploys

    0 讨论(0)
提交回复
热议问题