terinjokes/gulp-uglify

Unexpected token: keyword (const)

Closed this issue Β· 7 comments

Getting the following error while using uglify

GulpUglifyError: unable to minify JavaScript     
Caused by: SyntaxError: Unexpected token: keyword (const)

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

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

[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

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()

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

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 :)

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