Ralph Ralph - 9 months ago 111
Javascript Question

UglifyJS2 thows parse error (Unexpected token: name (Abide)) everytime

I try to use uglifyJS2 to concatenate all JavaScript files (from ZURB Foundation 6 including some custom ones) into one single file.

In an upcoming project I can't simply use ZURB's Yeti Launch application. So I plan to use both sass for

files (works already) and
for JavaScript files over command line.

Unfortunately I can't get uglifyjs2 to concatenate the scripts by fire the following command in command line:

uglifyjs foundation-sites/js/*.js -o foundation-stes/dist/foundation.min.js

It throws the following error even if I input only one single file (like foundation.abide.js):

Parse error at foundation-sites/js/foundation.abide.js:10,6
Unexpected token: name (Abide)
at new JS_Parse_Error (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:1526:18)
at js_error (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:1534:11)
at croak (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2026:9)
at token_error (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2034:9)
at unexpected (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2040:9)
at semicolon (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2060:56)
at simple_statement (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2240:73)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2113:19)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2073:24)
at block_ (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:2353:20)

But if I write some basic scripts it works perfectly. Is there anything I'm doing wrong? Is anybody able to hive me a helpful hint?

Answer Source

You need to transform ES6 to ES5 before using uglifyjs. At the moment uglifyjs does not support ES6 syntax. You can use babel for it. See more https://babeljs.io/.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download