languageEnglish

GulpUglifyError: unable to minify JavaScript

visibility 158 comment 0 access_time 4 months ago

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. 

Resolution

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.


copyright This page is subject to Site terms.

Subscribe newsletter

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext