ExecJS :: ProgramError: Unexpected token punc "(", expected punc ":" when starting rake assets: precompilation in production

When deploying my Rails application, the following error appears:

rake aborted! ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» (line: 15, col: 14, pos: 265) Error at new JS_Parse_Error (/tmp/execjs20150524-4411-1p45n63js:2359:10623) at js_error (/tmp/execjs20150524-4411-1p45n63js:2359:10842) at croak (/tmp/execjs20150524-4411-1p45n63js:2359:19086) at token_error (/tmp/execjs20150524-4411-1p45n63js:2359:19223) at expect_token (/tmp/execjs20150524-4411-1p45n63js:2359:19446) at expect (/tmp/execjs20150524-4411-1p45n63js:2359:19584) at /tmp/execjs20150524-4411-1p45n63js:2359:28513 at /tmp/execjs20150524-4411-1p45n63js:2359:19957 at expr_atom (/tmp/execjs20150524-4411-1p45n63js:2359:27269) at maybe_unary (/tmp/execjs20150524-4411-1p45n63js:2359:30019)new JS_Parse_Error ((execjs):2359:10623) js_error ((execjs):2359:10842) croak ((execjs):2359:19086) token_error ((execjs):2359:19223) expect_token ((execjs):2359:19446) expect ((execjs):2359:19584) (execjs):2359:28513 (execjs):2359:19957 expr_atom ((execjs):2359:27269) maybe_unary ((execjs):2359:30019) 

The file in question is valid, it runs on localhost. I also tried running rake assests:precompile on localhost, all this goes through. Finally, I tried to remove the contents from the file, git push and redeploy - still got the same error. Only full file deletion and redeployment helps.

Would thank for any ideas.

+43
git javascript ruby-on-rails deployment execjs
May 24 '15 at 10:24
source share
6 answers

Here I found help on the same problem as yours.

Launch the 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)) end 

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

+144
Jul 27 '16 at 6:42
source share

I suspect that in this js file you have something like the following:

 var User = { getName() { alert("my name"); } } 

Replacing it in the desired format,

 var User = { getName: function() { alert("my name"); } } 

worked for me.

The error clearly says that it expects a ":", but it has detected a "(".

+25
Sep 12 '15 at 1:03
source share

I'm not sure about your build chain, but I came here by pasting the same error message on Google.

This is called “shorthand properties” in ES2015. I am using Babel 6 with Gulp and you need to do npm install babel-plugin-transform-es2015-shorthand-properties --save-dev and add this conversion 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

+6
Jun 27 '16 at 10:42 on
source share

I could use https://skalman.imtqy.com/UglifyJS-online/ to determine the correct line number where the problem was. Fortunately, at least the correct file that had the problem was marked by grunt uglify

+5
Mar 15 '17 at 6:41
source share

Just meet the same problem.

In my case, syntax is used, which is only supported with ES2015, ex

 function someThing(param = true) { // do something here }; 

although this is not supported in our environment.

And error messages are actually generated by Uglifer.

+4
Apr 11 '16 at 11:16
source share

In my case, the problem is with the function definition like,

 function someFunctionName(param1, param2=defaultValue){ //code } 

Due to the above definition of the function, I got an error because it is not supported by Uglifier. The default parameters are the ES6 / ES2015 language specification.

To solve the above problem, you can refer to Set a default value for the JavaScript function

+2
Jul 10 '17 at 13:00
source share



All Articles