Raymond Raymond | Frontend & JavaScript

GulpUglifyError: unable to minify JavaScript

event 2021-05-28 visibility 2,828 comment 0 insights toc
insights Stats
toc Table of contents

Issue context

When using Gulp Uglify to minimize JavaScript script files, the following error is throw out:

GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token: keyword ¬ęconst

The root cause is that Uglify is not up to date and doesn't support es6. For this case, const keyword is not supported. 


One workaround is to replace Ugnify with gulp-terser

Follow these steps to do that:

  1. Install gulp-terser by updating package.json or use npm commands.
      "devDependencies": {
        "gulp": "^4.0.0",
        "gulp-concat": "2.6.1",
        "gulp-cssmin": "0.2.0",
        "rimraf": "2.6.1",
        "gulp-sass": "4.0.2",
        "gulp-google-webfonts": "4.0.0",
        "gulp-terser": "2.0.1"

    Npm commands:

    npm install gulp-terser --save-dev
  2. Replace uglify function with terser:
    const uglify = require("gulp-terser");

    With this approach, you don't need to replace function uglify.

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts