错误:意外标记:punc() [英] Error: Unexpected token: punc ()

查看:44
本文介绍了错误:意外标记:punc()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建使用 webpack 的项目.我的 UglifyJS 选项如下所示:

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,
              },
            },
          }),

我得到的是一个错误:意外令牌:punc()) [index-3d0ae630eaa0a0128a00.js:145853,20]

我发现一些 SO 主题说这可能是 webpack uglify 插件的问题,但我已经切换到 uglifyjs-webpack-plugin.

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.

有什么想法吗?

推荐答案

我遇到了同样的错误,并且能够通过以下方式修复它:

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

  1. 升级到 1.0.0-beta.2 (npm i -D uglifyjs-webpack-plugin@beta)
  2. babel-preset-env
  3. 中的targets中添加"uglifyjs": true

如果您使用的是 env 预设,请尝试更新您的 .babelrc 中的目标:

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.

这篇关于错误:意外标记:punc()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆