digitalsparky / jekyll-minifier

Jekyll HTML/XML/CSS/JS Minifier utilising yui-compressor, and htmlcompressor
GNU General Public License v3.0
245 stars 25 forks source link

Error on minify JS file when building Jekyll site #17

Closed serebit closed 5 years ago

serebit commented 7 years ago

Here's the stack trace:

Configuration file: /home/ubuntu/workspace/_config.yml
Configuration file: /home/ubuntu/workspace/_config.yml
            Source: /home/ubuntu/workspace
       Destination: /home/ubuntu/workspace/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
jekyll 3.3.1 | Error:  Unexpected token: operator (>) (line: 37, col: 45, pos: 2205)

Error
    at new JS_Parse_Error (/tmp/execjs20170119-3146-pk4md0js:2659:11936)
    at js_error (/tmp/execjs20170119-3146-pk4md0js:2659:12155)
    at croak (/tmp/execjs20170119-3146-pk4md0js:2659:20622)
    at token_error (/tmp/execjs20170119-3146-pk4md0js:2659:20759)
    at unexpected (/tmp/execjs20170119-3146-pk4md0js:2659:20847)
    at expr_atom (/tmp/execjs20170119-3146-pk4md0js:2659:29141)
    at maybe_unary (/tmp/execjs20170119-3146-pk4md0js:2659:31652)
    at expr_ops (/tmp/execjs20170119-3146-pk4md0js:2660:404)
    at maybe_conditional (/tmp/execjs20170119-3146-pk4md0js:2660:496)
    at maybe_assign (/tmp/execjs20170119-3146-pk4md0js:2660:939)

If I disable parsing JS using _config.yml, the error does not occur.

digitalsparky commented 7 years ago

Hi!

This issue generally only occurs due to a parsing failure in the javascript.

The error message is showing you is that there is a syntax error in your javascript on line 37 which it is unable to parse and recover from, therefore throwing an error.

I recommend analysing your javascript to ascertain where the syntax error is occuring and correcting that.

The easiest way to do this is to use dev tools on your browser.

Hope that helps

Matt

serebit commented 7 years ago

If I'm correct, the error is caused by this line:

response.forEach(data => addDownload(data));

This is valid ES6 syntax.

digitalsparky commented 7 years ago

Hi there,

Yeah, you're correct, however it appears that the library I'm using for minification of JS does not support ES6 as yet.

https://rubygems.org/gems/uglifier - https://github.com/lautis/uglifier

It is being actively developed, so it may be best to contact them to see if they're able to add support.

Matt

pirafrank commented 6 years ago

I second to this, adding the following lightly different error. I hope it helps debugging jekyll 3.7.2 | Error: SyntaxError: Unexpected token: operator (<)

garciparedes commented 6 years ago

I'm having the same bug. The JS minifier neither recognises properly the let token on cases like this: let a = 3.

netEmmanuel commented 5 years ago

I have the same issue. I can't use arrow function or let keyword

Yankie commented 5 years ago

Confirm that issue. My code has: let n = Math.abs(number); Also, seems like uglifier is updated to 4.1.18 (you demand ~> 3.2)

And one more thing: When using Uglifier with ES6 syntax without any options, an error will be thrown. (source: https://github.com/lautis/uglifier) So, maybe it could be better to provide some config option or encourage users to use ES6...

digitalsparky commented 5 years ago

ES6 is now supported by upstream, I've opened up the settings to be able to change harmony on uglifier etc.

kroschu commented 5 years ago

jekyll 3.8.5 | Error:

Whan i try bundle exec jekyll build JEKYLL_ENV="production" --watch --incremental

digitalsparky commented 5 years ago

@kroschu

try this:

JEKYLL_ENV="production" bundle exec jekyll build  --watch --incremental

Environment variables go at the beginning, before the command. you can also set them in your terminal and just run your commands as normal.

Matt