当我尝试使用gulp和uplift-js构建项目时代码失败

时间:2017-09-22 17:19:47

标签: javascript gulp gulp-uglify

我正在使用gulp和uglify-js构建我的项目,但它失败了,无法构建。我无法找到这个小代码片段的问题。

功能:

function getOneSignalToken() {
    window.bridge.post('onesignaltoken', {},     (results, error) => {
         $('#onesignal_token').html(results.token);
    });
}

错误

events.js:160
  throw er; // Unhandled 'error' event
  ^

错误     在新的JS_Parse_Error(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:1545:18)     在js_error(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:1553:11)     在croak(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2092:9)     at token_error(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2100:9)     在意外(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2106:9)     at expr_atom(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),: 2633:9)     在maybe_unary(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2795:19)     at expr_ops(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),: 2830:24)     在maybe_conditional(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2835:20)     在maybe_assign(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2859:20)     at maybe_assign(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),: 2867:32)     at expression(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),: 2878:20)     at expr_list(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),: 2644:24)     在下标(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2778:30)     在下标处(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2755:20)     在下标处(eval at(/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2755:20) Eriks-MacBook-Pro:nat5 erik $

2 个答案:

答案 0 :(得分:1)

转换为pre es6 / es2015语法

(results, error) => {...}

将成为

function(results, error) {...}

要使用新款es2015 gulp,请参阅:https://markgoodyear.com/2015/06/using-es6-with-gulp/

如果你想升级uglify-js以支持es6,请使用uglify-es npm包:https://www.npmjs.com/package/uglify-es

答案 1 :(得分:0)

正如@peter悲伤..这解决了问题:

SecurityContext