0

I am geting to build my project with gulp and uglify-js but it fails and can’t build. And I can’t find what is wrong with this small code snippet.

Function:

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

Error

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

Error at new JS_Parse_Error (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1), :1545:18) at js_error (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1), :1553:11) at 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) at unexpected (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) at 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) at maybe_conditional (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1),:2835:20) at 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) at subscripts (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1), :2778:30) at subscripts (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1), :2755:20) at subscripts (eval at (/Users/erik/Desktop/Erik/code/nat5/node_modules/uglify-js/tools/node.js:28:1), :2755:20) Eriks-MacBook-Pro:nat5 erik$

5
  • Does your version of gulp and uglify-js support es2015? Commented Sep 22, 2017 at 17:21
  • If not then change (results, error) => to function(results, error) and try again Commented Sep 22, 2017 at 17:22
  • Add the error you are getting otherwise so we can help you debug Commented Sep 22, 2017 at 17:23
  • Where do I see the version? Also updated the question with the error log Commented Sep 22, 2017 at 17:25
  • Thanks for the help, it works now! Love it! Commented Sep 22, 2017 at 17:30

2 Answers 2

1

Converting to pre es6/es2015 syntax

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

will become

function(results, error) {...}

To use gulp with new style es2015 see: https://markgoodyear.com/2015/06/using-es6-with-gulp/

And if you want to upgrade uglify-js to support es6 use the uglify-es npm package: https://www.npmjs.com/package/uglify-es

Sign up to request clarification or add additional context in comments.

Comments

0

As @peter sad.. this fixed the problem:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.