GulpUglifyError: unable to minify JavaScript
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:
- 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
- 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.
comment Comments
No comments yet.
Log in with external accounts
warning Please login first to view stats information.
article
Chrome: Uncaught SyntaxError: Unexpected end of input
article
jQuery Unobtrusive Validation with Bootstrap 5 CSS
article
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 12.x
article
JavaScript + XSLT 解析XML为HTML的方法
code
Vanilla JavaScript - Wildcard (*) Selector
Read more (13)