最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - UglifyJs unexpected token error - Stack Overflow

programmeradmin3浏览0评论

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 es up there. Now, how can i solve this problem as I have already included babel-loader preset es2015 to convert es6 to es5.

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 es up there. Now, how can i solve this problem as I have already included babel-loader preset es2015 to convert es6 to es5.

Share Improve this question asked Mar 18, 2018 at 12:10 ANURAG GUPTAANURAG GUPTA 1931 silver badge13 bronze badges 3
  • Can you tell us what is the error text you are getting at the token let ? – S Raghav Commented Mar 18, 2018 at 12:26
  • UglifyJs failure, Unexpected token error: name (xyz) @raghav710 – ANURAG GUPTA Commented Mar 18, 2018 at 14:54
  • I have fixed the issue as described in the following thread stackoverflow./questions/61606913/… – Julian Eduardo de Anquin Commented Jan 22, 2021 at 13:24
Add a ment  | 

2 Answers 2

Reset to default 3

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.

Use terser-webpack-plugin for minifying ES6 code

发布评论

评论列表(0)

  1. 暂无评论