I am having issues pushing my rails project to heroku. I get a \"Precompiling assets failed\" message . I am new to programming and new to ruby on rails. I really need some
The error message indicates that one of your JavaScript (or CoffeeScript) files has a syntax error. Unfortunately, the message doesn't give you enough information to locate the correct asset and line number. However, you can narrow down your search by precompiling locally with
rake assets:precompile
Which should output something similar to
ExecJS::RuntimeError: Unexpected token: operator (=)
(in /path/to/railsapp/app/assets/javascripts/path/to/asset.js)
...
This indicates that the error is in the file path/to/asset.js
. Without knowing the contents of this file, I can only guess that you have a misplaced =
somewhere in there. Take a closer look at that file and see if anything looks out of place.
Keep in mind, running rake assets:precompile
locally will generate assets in public/assets/
. You do not want to check those into your git repository, be sure to delete them before committing your fix to the broken asset file.
Search for operator = in your JavaScript. You will provably find typo with = then.
remote: rake aborted! remote: ExecJS::ProgramError: Unexpected token: operator (=) (line: 10770 , col: 0, pos: 300859)
You probably already solved this by now, but I stumbled across this issue and wanted to share my solution.
As an answer above suggested, the best way to track the error down to the problematic file is to run
rake assets:precompile RAILS_ENV=production
locally while excluding files or directories you might think contain the problem. I deleted directories one by one (which I could later checkout again from my repo) until I got the precompilation running. I then drilled down into the last deleted directory and tracked it down to a certain file and a function of the form
array.find(name => name.id === user_id);
My research showed that it turns out the largest update to Javascript (ES5) was released in 2009 and since then, only unitl June 2015 was the ECMAScript 6 (ES6) final specification released. The syntax used in this function is supported by ES6 but not ES5 and ES6 is not yet supported on Rails (I was running RoR 5.0.0.1), at least not with ExecJS on the assets pipeline.
What you CAN do, is change your function to an alternative syntax, namely
array.find(function(name){return name.id === user_id});
and it should work equivalently.
find
function hereI had a very similar problem and as mentioned its because my version of Rails did not support ES6. Upgrading sprockets din work for me though. What I ended up doing was upgrading uglifier
and in my production.rb
, changing,
config.assets.js_compressor = :uglifier
to
config.assets.js_compressor = Uglifier.new(harmony: true)
And then my precompile worked like a charm.
I think its the same problem as this: ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (>) (line: 22342, col: 24, pos: 826182)
I had a very similar issue where it wouldn't let me precompile because of a (>). I pretty much tracked offending file by deleting different files and seeing if a precompile would work. Eventrually I tracked it down to this method:
tagIsUnique: function(){ return this.tags.findIndex( item => this.tag.toLowerCase() === item.toLowerCase() ) < 0; }
and then I changed it so that it no longer had the offending arrow in it.