Search code examples
javascriptvisual-studio-2015gulpgulp-uglify

GulpUglifyError using gulp-webpack-vs2015


I am having following error

events.js:160
      throw er; // Unhandled 'error' event
      ^
GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token: punc ({) (line: 15, col: 7, pos: 1014)
Error
    at new JS_Parse_Error (eval at <anonymous> (C:\..\node_modules\gulp-uglify\node_modules\uglify-js\tools\node.js:1:0), <anonymous>:1545:18)

package.json

"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.1.0",
"gulp-sourcemaps": "^2.1.1",
"gulp-typescript": "^3.0.2",
"gulp-uglify": "^2.0.0",
"uglify-js-harmony": "^2.6.2"

After looking for answers it looks like gulp-uglify relies on UglifyJS Issue with Babel, ES6 and Uglify, thus it does not work properly. On the other hand they encourage to use uglify-js-harmony instead. But still is looking at gulp-uglify\node_modules\uglify-js. How can I force gulp to point to uglify-js-harmony instead?

Thank you


Solution

  • This issue is related with my other question Gulp error with angular2, also it is necessary to deploy only needed files, or in the above case exclude node modules folder as:

    tsconfig.json

    "files": [
        "angularApp/app/app.module.ts",
        "angularApp/main.ts"
      ],
    

    or excluding (better include only need files rather than excluding all node modules)

    "exclude": [
        "node_modules"
      ]