ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» when running rake assets:precompile on production

Here I found help for the same problem you had.

Run rails console and:

JS_PATH = "app/assets/javascripts/**/*.js"; 
Dir[JS_PATH].each do |file_name|
  puts "\n#{file_name}"
  puts Uglifier.compile(File.read(file_name), harmony: true)
end

It will show you the file and the line where the Uglifier is making the problem.


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.


I'm not sure of your build chain, but I got here by pasting the same error message into Google.

That is called 'shorthand properties' in ES2015. I'm using Babel 6 with Gulp and needed to do an npm install babel-plugin-transform-es2015-shorthand-properties --save-dev and add that transform to my babel plugins.

.pipe(babel({
    plugins: [
        'transform-es2015-shorthand-properties'
    ]
}))

https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-shorthand-properties


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