Error pushing Rails application to Heroku - ruby-on-rails

I'm doing an application in RoR from Linux/Ubuntu and deploying in Heroku but when I try to push to Heroku I get this error:
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:herokuangelapp.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:herokuangelapp.git'
Thanks for your help.

Precompilation
Without knowing the exact error, the question arises as to what the error itself is saying. The problem you have is Heroku's precompilation system won't be able to precompile the assets for your Rails application (obviously)
The causes of this could be numerous, but the main culprit is that you have syntax errors in your asset files, preventing them from being precompiled.
--
Local
As recommended in the comments, you should precompile the assets locally using the following command:
$ rake assets:precompile RAILS_ENV=production
This will run the precompilation process on your local machine, and will return any exceptions that occur throughout the process.
In order to get it working, you need to clean up any of the syntax errors which are returned with this local precompilation process

Related

git push heroku master is rejected and faild to compile ruby app

Did some research but can't figure out what caused the rejection when I tried to git push heroku master.
Here is my the git repo: https://github.com/leonahu/IMGfeed
and this is the details of the rejection:
remote: Tasks: TOP => environment
remote: (See full trace by running task with --trace)
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to feedimg.
remote:
The error says that the assets failed to precompile, so you should precompile them by running bundle exec rake assets:precompile
Or specifically for production run RAILS_ENV=production bundle exec rake assets:precompile
Make sure that you have this line of code in your config/application.rb file: config.assets.initialize_on_precompile = false
After this, try to push to heroku again
I think you might forget to set config.secret_key_base in production. Run:
heroku config:set SECRET_KEY_BASE=your_secret_key_base
To get a new secret key you can run bundle exec rake secret in the project's root folder.
I tried all the suggestions above but it did not work on my app ( Thanks everyone who tried to help nevertheless.)
What ended up working for me is I basically forced the Heroku by running:
git push heroku master --force
After that, I was able to git push heroku master again.

Heroku Precompiling asset with rails

I found this error while running "git push heroku master". I have tried all the available solutions on stackoverflow but doesn't work for me.
gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:60:in `block (2 levels) i
n define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:aqueous-eyrie-6143.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:aqueous-eyrie- 6143.git'
here is my production log
You should run the rake assets:precompile RAILS_ENV=production on your local machine and look at the production.log for possible errors before pushing to heroku

Heroku rejects my git push request

So I created a Rails 4 app and was able to push it upstream to Heroku properly the first time. Every since then I haven't been regularly pushing my changes. I just got to a very significant checkpoint and decided to try to push my changes to the actual site on heroku but it rejects my request saying that it failed to compile my Ruby app. I've copy and pasted some of the feedback my command line provided me with in hopes that someone has had a similar error and can give me some ideas as to what might be wrong. Thanks in advance.
Running: rake assets:precompile
rake aborted!
ExecJS::ProgramError: Unexpected token name «users», expected punc «,» (line: 11341, col: 35, pos: 318042)
Error
at new JS_Parse_Error (/tmp/execjs20140625-619-93tzcv.js:2357:10754)
at js_error (/tmp/execjs20140625-619-93tzcv.js:2357:10973)
at croak (/tmp/execjs20140625-619-93tzcv.js:2357:19198)
at token_error (/tmp/execjs20140625-619-93tzcv.js:2357:19335)
at expect_token (/tmp/execjs20140625-619-93tzcv.js:2357:19558)
at expect (/tmp/execjs20140625-619-93tzcv.js:2357:19696)
at expr_list (/tmp/execjs20140625-619-93tzcv.js:2357:27763)
at /tmp/execjs20140625-619-93tzcv.js:2357:29817
at /tmp/execjs20140625-619-93tzcv.js:2357:27576
at /tmp/execjs20140625-619-93tzcv.js:2357:30108
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:picritique.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:picritique.git'
A similar error occurred to me recently when deploying a rails 4 app on heroku, and what I did was to precompile the assets in my local machine and then send them to heroku.
Try to do in your local:
rake assets:precompile
git add .
git commit -m 'assets precompiled locally'
git push heroku master
And it worked. I haven't figured the reason yet to do this, so any insight on this will be appreciated. It just worked for me in this way.
Seems like maybe you've got an error in your JavaScript. Are you able to run RAILS_ENV=production rake assets:precompile --trace locally?
I was making mistake in code as below
_companyService.get({companyId },function(result) {...
Fixed it as
_companyService.get({ companyId: companyId },function(result) {...

Getting Error while pushing into Heroku (Precompiling assets failed.)

Note: I am using Rails 3.2.13 and Ruby "1.9.3", and postgres-0.15.1
I tried to push my Ruby on Rails app in to heroku by following the procedure this website
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-deploying
, but I got error while try to push into heroku
Connecting to database specified by DATABASE_URL
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?
! Precompiling assets failed.
! Push rejected, failed to compile Ruby app
To git#heroku.com:pure-hamlet-9148.git
! [remote rejected] master -> master (pre-receive hook declined)
So, I Googled myself and run the below command
heroku labs:disable user-env-compile
heroku labs:enable user-env-compile
Still getting the same error, please some help me to resolve this issue.
Along with Simone's answer,
Follow this website to precompile your assets locally before deploying. https://devcenter.heroku.com/articles/rails-asset-pipeline
RAILS_ENV=production bundle exec rake assets:precompile
git add public/assets -f
git commit -m "vendor compiled assets"
Check this article about Heroku and Rails asset:precompile error. You should set
config.assets.initialize_on_precompile = false
A way to resolve this error:
First of all set DATABASE_URL environment variable & then again tried to push code to Heroku again. And it worked as all rake compilation done at Heroku side so no more connection to local machine making rake compilation # .../tmp/bin..... directory.

Ruby on Rails Precompiling assets failed

I've been following the reInteractive ruby on rails (15 min blog), and in the end of the post (second part), I got an error using heroku to upload my files:
! Precompiling assests failed
!Push rejected, failed to compile Ruby app
To git#heroku.com:peaceful-sea-8032.git
! [remote rejected] master -> master <pre-receive hook declined>
error: failed to push some refs to 'git#heroku.com:peaceful-sea-8032.git'
ps: The app runs fine on localhost, I saw some similar question but I did not have success trying their solutions.
Precompile your assets locally. In your shell cd to your application folder and enter:
RAILS_ENV=production bundle exec rake assets:precompile
This will precompile your assets locally
Then you have to
git add .
git commit -am 'precompiled assets'
git push heroku
(eddited last line)

Resources