Uglify SyntaxError: Unexpected token: punc ())

Uglify SyntaxError: Unexpected token: punc ())(Uglify SyntaxError: Unexpected token: punc ()))
本文介绍了Uglify SyntaxError: Unexpected token: punc ())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gulp 来缩小包含 JS 文件的文件夹.但是,其中一个文件存在上述错误,导致无法对其进行缩小.

I am trying to use gulp in order to minify a folder containing JS files. However, one of the files has the above error, preventing it from being minified.

我设法捕获并打印了错误,我在此处部分打印了该错误:

I managed to catch and print the error, which I've partially printed here:

JS_Parse_Error {
 message: 'SyntaxError: Unexpected token: punc ())',
 filename: 'ex.js',
 line: 189,
 col: 25,
 pos: 6482,
 stack: Error
    at new JS_Parse_Error (eval at <anonymous> ... ) 
 plugin: 'gulp-uglify',
 fileName: '.../js/ex.js',
 showStack: false
}

相关文件包含以下内容,已缩短:

The file in question contains the following, shortened:

function() {
  ...
  $.confirm({
    buttons: {
        confirm: function() {
            $.post('/ajax-handler', {
                    ...
                })
                .done( function(response) {
                    var data = filterResponse(response);
                    if (data['status'] == 'success') {
                        sleep(1000).then(() => {
                    *       ...
                        });
                        sleep(5000).then(() => {
                            ...  
                        });

                    } else {
                        console.log('Oops!');
                    }
                })
                .fail( function(err, status, response) {
                    ...
            });
        },
        cancel: function() {}
    }
 });
  ...
}

我在上面添加了*"以指示 JS_Parse_Error 列出的确切位置.

I added the "*" above in order to indicate the exact position listed by JS_Parse_Error.

推荐答案

//更新

来自评论~ @imolit

切换回 uglify-js(uglify-es 已弃用,如果需要 uglify ES6 代码请使用 terser-webpack-plugin).

网页包

要与 webpack 一起使用,还要安装 webpack 插件


Webpack

To use it with webpack install also the webpack plugin

npm install uglifyjs-webpack-plugin --save-dev

yarn add uglifyjs-webpack-plugin --dev

然后导入手动安装的插件

then import the manually installed plugin

var UglifyJSPlugin = require('uglifyjs-webpack-plugin');

并在代码中替换它

-  new webpack.optimize.UglifyJsPlugin({ ... })
+  new UglifyJSPlugin({ ... })

<小时>

有关更多 webpack 信息(安装/使用),请参阅 https://github.com/webpack-contrib/uglifyjs-webpack-plugin#install

这篇关于Uglify SyntaxError: Unexpected token: punc ())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)