26

I need help. When trying to upload my app to heroku, I get this error, anyone know why? A few was wrong. thanks

       Using rake (10.1.0)
       ...
       Using tlsmail (0.0.1)
       Using uglifier (2.1.2)
       Your bundle is complete! It was installed into ./vendor/bundle
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
       ...
       /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession
       DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/Rakefile:7)
       ...
       rake aborted!
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?
       /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
       /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
       ...
       /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
sebabentancurt
  • 263
  • 1
  • 3
  • 6

4 Answers4

33

From the Heroku docs:

This means that your app is attempting to connect to the database as part of rake assets:precompile. Because the config vars are not present in the environment, we use a placeholder DATABASE_URL to satisfy Rails.

To resolve this issue, ensure that the following line appears in your config/application.rb:

# config/application.rb
config.assets.initialize_on_precompile = false

Once added, commit your change and redeploy to Heroku – your assets should compile without your app attempting to connect to the database, which should resolve the error you're witnessing.

UPDATE:

Line 46 of your stacktrace includes the following message: Devise.secret_key was not set.

According to the author of Devise, José Valim, this issue can be resolved in the following manner:

Please add the following to your Devise initializer:

config.secret_key = '-- secret key --'

Alternatively, the following solution seems to have worked for a number of users:

I went to my routes.rb file and commented out the line devise_for :installs

Then I went back and reran rails generate devise:install. If that doesn't work, use the previous version of devise by editing your Gemfile's reference to Devise like this: gem 'devise', '3.0.3' and then follow the steps i mentioned above.

Community
  • 1
  • 1
zeantsoi
  • 25,857
  • 7
  • 69
  • 61
  • Hello, I did what you said and did upload, but failing that walketh in heroku. – sebabentancurt Oct 29 '13 at 17:19
  • Hello, thank you very much for your help. I get error on heroku. to enter the page, I routed the default error page in heroku. With config.assets.initialize_on_precompile = false does not go up but the app (Application Error An error occurred in the application and your page Could not be served. Please try again in a few moments. If you are the application owner, check your logs for details.) No config.assets.initialize_on_precompile = false, I get this error when uploading:http://pastebin.com/6DAcmNxS – sebabentancurt Oct 30 '13 at 02:51
  • Log the heroku in app: http://pastebin.com/9cJsejc2 (With config.assets.initialize_on_precompile = false) – sebabentancurt Oct 30 '13 at 03:51
  • Please see my update. If this answer helps address your issue, please consider accepting it as correct: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – zeantsoi Oct 30 '13 at 05:28
  • Hello, thanks for you help. If I disable the precompile, I do not compile error javascript. any idea? – sebabentancurt Nov 06 '13 at 20:36
  • I'm afraid I don't understand what the problem is. Can you post your stack trace? Also, note that you're not disabling the precompile itself – you're disabling _initialization_ upon precompilation. – zeantsoi Nov 06 '13 at 21:05
  • WHERE does that line go within that file? – JGallardo Nov 07 '13 at 00:37
  • 2
    @JGallardo: anywhere within the `class Application < Rails::Application` block. – zeantsoi Nov 07 '13 at 00:46
18

There a few things that solved this issue for me:

# config/application.rb
config.assets.initialize_on_precompile = false

Then, before I deployed, I compiled my assets locally and committed them:

RAILS_ENV=production bundle exec rake assets:precompile

Also, I installed this heroku add on, as was specified by the app I was launching (in my case, Spree commerce)

heroku labs:enable user-env-compile -a myapp

And of course, make sure your database.yml file is set to use adapter: postgresql.

Commit all of this, push to heroku, and hopefully it will launch. If you still cannot open your app, try looking at the Heroku logs: heroku logs -n 500

I still needed to migrate my database with heroku run rake db:migrate

Danny
  • 3,982
  • 1
  • 34
  • 42
3

when you are using github and you are pushing to heroku while you are in develop branch, dont do it, go to master branch and get the updates in the develop by git merge develop

after that,

rails precompile:assets
git add -A
git commit -m "Precompile assets"
git push heroku master

if you want to open the website that you deployed

heroku open

if nothing shows, migrate your database first by:

heroku run rails db:migrate
heroku open
noe
  • 194
  • 1
  • 9
1

I have failed Heroku proceompiling with same error message. Carrierwave causes that because I have missed set up SECRET_KEY_BASE to Heroku setting.

Shun Yamada
  • 879
  • 1
  • 10
  • 25
  • From Review: Hi, this post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer and improve it, or just post it as a comment. – sɐunıɔןɐqɐp Oct 23 '18 at 06:45