terinjokes / gulp-uglify

Minify files with UglifyJS
MIT License
1.23k stars 154 forks source link

Unexpected token: keyword (const) #352

Closed themeix closed 3 years ago

themeix commented 5 years ago

Getting the following error while using uglify

GulpUglifyError: unable to minify JavaScript     
Caused by: SyntaxError: Unexpected token: keyword (const)
aheiland commented 5 years ago

gulp uglify uses node 4 - const/let is a knowen error of node below 5.3.0 - issue could be resolved by update node dependencie

legendarydrew commented 4 years ago

Adding minify as a dependency (I have ^4.1.3) seemed to have fixed this problem.

avinzheng commented 4 years ago

[20:36:24] GulpUglifyError: unable to minify JavaScript Caused by: SyntaxError: Unexpected token: keyword «const»

My node version:

$ node -v
v12.18.1

My Gulp version:

$ yarn list --pattern=gulp       
yarn list v1.22.4
......
├─ gulp@4.0.2
......

My gulp-uglify version:

$ yarn list --pattern=gulp-uglify
yarn list v1.22.4
└─ gulp-uglify@3.0.2
svivian commented 3 years ago

For anyone finding this through Google, this project is dead. The replacement is gulp-terser which supports modern JS features. It's basically a drop-in replacement - install it, add const terser = require('gulp-terser'); to your gulpfile, then you can just replace uglify() with terser()

terinjokes commented 3 years ago

This project is not dead. It still supports UgliftyJS, and the many forks of UgliftyJS, some of which are mentioned above. It will continue to adapt to continue working with future releases of UgliftyJS and Node.js

svivian commented 3 years ago

Oh, apologies. UglifyJS is dead though, it doesn't support any JS from the past 5 years. And the version that supposedly replaced it (uglify-es) explicitly states to use terser instead. So the OP won't solve their problem with this plugin.

But a huge thanks from me for making this plugin, it's served me well for many years :)

terinjokes commented 3 years ago

You can use this plugin with terser, as shown on the README. At least it worked the last time I tried.