Error: Unexpected token: punc ()

混江龙づ霸主 提交于 2020-01-04 04:43:06

问题


I'm trying to build my project that uses webpack. My UglifyJS options looks like this:

new UglifyJSPlugin({
            sourceMap: false,
            uglifyOptions: {
              compress: {
                warnings: false,
              },
              output: {
                comments: false,
              },
            },
          }),

What I get is an error: Unexpected token: punc ()) [index-3d0ae630eaa0a0128a00.js:145853,20]

I have found some SO topic saying that this might be a problem with webpack uglify plugin, but I've already switched to an uglifyjs-webpack-plugin.

Any ideas?


回答1:


I had the same error and was able to fix it by:

  1. Upgrading to the 1.0.0-beta.2 (npm i -D uglifyjs-webpack-plugin@beta)
  2. Adding "uglifyjs": true to the targets in babel-preset-env

If you're using the env preset, try updating the targets in your .babelrc:

{
  "presets": [
    [
      "env",
      {
        "targets": {
          "uglify": true
        }
      }
    ]
  ]
}

There is also an issue on the plugin repo that lists other possible solutions.



来源:https://stackoverflow.com/questions/45781808/error-unexpected-token-punc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!