frshjb373
frshjb373

Reputation: 627

Javascript error when using Gulp Uglify with js array

I'm getting the following error when running uglify in Gulp. Not getting an error when calling this same code in script in head of document. Please advise how to fix error.

Error in terminal:

 { SyntaxError: Unexpected token punc «,», expected punc «:»
     at JS_Parse_Error.get (eval at <anonymous> (/Applications/MAMP/htdocs/site.com/node_modules/uglify-js/tools/node.js:1:0), <anonymous>:86:23)
     at formatError (util.js:644:15)
     at formatValue (util.js:550:18)
     at formatProperty (util.js:790:15)
     at util.js:650:12
     at Array.map (native)
     at formatObject (util.js:649:15)
     at formatValue (util.js:589:16)
     at inspect (util.js:183:10)
     at exports.format (util.js:69:24)
   message: 'Unexpected token punc «,», expected punc «:»',
   filename: 'jquery.main.js',
   line: 104,
   col: 18,
   pos: 2671 },
plugin: 'gulp-uglify',
fileName: '/Applications/MAMP/htdocs/site.com/src_assets/js/jquery.main.js',
showStack: false }

Javascript Error on line: 104 is referring to line playerVars,:

  window.onYouTubeIframeAPIReady = function() {
      playerVars = { 'autoplay': 1, 'controls': 0, 'rel': 0, 'showinfo': 0, 'loop': 1, 'modestbranding': 1 };

      return new YT.Player('youtubeVideoPlayer', {
        height: playerHeight,
        width: playerWidth,
        videoId: player.data('video-id'),
        playerVars,
        events: {
            onReady: function(e) {
              frame = holder.find('iframe');
              e.target.mute();
              resizeHandler();
            }
          }
      });
  }

Upvotes: 1

Views: 310

Answers (1)

Barmar
Barmar

Reputation: 781096

Uglify apparently doesn't understand the ES6 shorthand playerVars for playerVars: playerVars.

I think you can resolve this by installing uglify-es. Or just replace the shorthand with the traditional syntax.

Upvotes: 2

Related Questions