Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR in bundle.js from UglifyJs Name expected

I am trying to use UglifyJS to minimize/compress my bundle.js file. When I run webpack -p, I am getting the following:

ERROR in bundle.js from UglifyJs Name expected [bundle.js:105519,6]

Line 105519 is as follows:

const {M, l, pattern} = __webpack_require__(862).

I am using React w/ ES6. Any thoughts as to what is wrong?

like image 765
Colby Cox Avatar asked Aug 24 '17 20:08

Colby Cox


1 Answers

Every version of Webpack has a built-in version of UglifyJS (0.4.6) which doesn't support ES6. This version supports ES5 syntax only.

There are two possible solutions:

  • Make transpiler target es5
  • Don't use the built-in version of uglifyjs-webpack-plugin and install the latest version using npm install -D uglifyjs-webpack-plugin. Add it to your plugins property in your configuration:

    const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
    
    module.exports = {
      plugins: [
        new UglifyJSPlugin()
      ]
    }
    
like image 169
Michał Pietraszko Avatar answered Nov 14 '22 16:11

Michał Pietraszko