When deploying my Rails app I get the following error:
rake aborted!
ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» (line: 15, col: 14
I suspect, in that js file, you have something like the following:
var User = {
getName() {
alert("my name");
}
}
Replacing it with the right format,
var User = {
getName: function() {
alert("my name");
}
}
worked for me.
Error is clearly saying, it's expecting ":" but it found "(".
Just encounter the same issue.
My case is someone used syntax that's only support since ES2015, ex
function someThing(param = true) {
// do something here
};
while this is not supported in our environment.
And the error messages is actually generated by Uglifer.
As the backtrace doesn't provide information about the corrupted file, for me the best way to identify the error is use git bisect.
It allows you to find the commit that introduces a bug.
Let's suppose you are on master, first you start git bisect:
$ git bisect start
$ git bisect bad
Then you go back to a previous, working revision, let's suppose 20 revision ago.
$ git checkout HEAD~20
You run the same command
$ RAILS_ENV=production rake assets:precompile
If it works you mark revision as good:
$ git bisect good.
git will jump to another revision, you run same command again (assets:precompile) and bassed on the output mark it as good / bad.
In less than 1 minute you should be able to find what's the commit that introduced the issue.
I could use https://skalman.github.io/UglifyJS-online/ to identify the correct line number where the issue was. Thankfully, at least the correct file which had an issue was pointed out by grunt uglify
In my case problem with function definition like,
function someFunctionName(param1, param2=defaultValue){
//code
}
Due to above function definition I was getting error, as it is not supported by Uglifier. Default parameters is ES6/ES2015 language specification.
For solution to above problem you can refer Set a default parameter value for a JavaScript function
Update uglifier gem to last version and update your production.rb
config.assets.js_compressor = Uglifier.new(harmony: true)