Error pushing to heroku - aborting my rake assets:precompile Error pushing to heroku - aborting my rake assets:precompile ruby-on-rails ruby-on-rails

Error pushing to heroku - aborting my rake assets:precompile


See the Rails 3.1+ Asset Pipeline on Heroku Cedar article. This exact scenario is covered in the Troubleshooting section.

In short, your Heroku application has a strong separation between building (including asset compilation) and running (where your application becomes available). This is consistent with the 12-factor app principles, but it means that your application cannot access any configured resources during the build phase -- including the database -- meaning ActiveRecord is unavailable during asset precompilation.

You can tell Rails not to bootstrap your application during asset compilation in config/application.rb:

config.assets.initialize_on_precompile = false

The troubleshooting section also recommends:

If rake assets:precompile is still not working, you can debug this locally by configuring a nonexistent database in your local config/database.yml and attempting to run rake assets:precompile. Ideally you should be able to run this command without connecting to the database.


I struggled with exactly the same problem, for hours tonight. After adding

config.assets.initialize_on_precompile = false

to application.rb, remember to do a

git commit

right afterwards. I forgot to do this, and Heroku had no idea I'd changed application.rb. They don't have this extra line on their troubleshooting page.


For Rails 4

Enable Heroku Labs feature to fix this problem

heroku labs:enable user-env-compile