Search code examples
javascriptreactjswebpackecmascript-6uglifyjs

UglifyJs unexpected token error


I have already used this in my webpack.config.js

use: [{
        loader: 'babel-loader',
        options: {
          presets: ['es2015', 'es2016', 'react']
        }
      }]

But still I am getting error at the token let which I have used.

I get that uglify doesn't understands ECMAScript-6

Now when i build my webpack with -p, i get the mentioned error, because uglify comes up there. Now, how can i solve this problem as I have already included babel-loader preset es2015 to convert es6 to es5.


Solution

  • As you've said, your current version of the Uglify plugin doesn't support ES6, so you'll need to upgrade. You have a few options:

    1. Upgrade to Webpack 4, which includes the new uglify plugin by default
    2. If you need to stay on v3 for whatever reason, you can follow the instructions on the docs here to install the new uglify plugin and use it manually.