ERROR in bundle.js from UglifyJs Name expected

Colby Cox picture Colby Cox · Aug 24, 2017 · Viewed 7.9k times · Source

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?

Answer

Michał Pietraszko picture Michał Pietraszko · Aug 30, 2017

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()
      ]
    }