Uglifyjs: ERROR: Unexpected token: keyword (const)

Created on 6 Dec 2017  路  4Comments  路  Source: mishoo/UglifyJS

const is a valid keyword. Not sure why something so simple is breaking this. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

Bug report or feature request? BUG
ES5 or ES6+ input? Not sure what this means. I'm not a big js developer
Uglify version (uglifyjs -V) 3.2.1
JavaScript input

[grr@othala js]$ cat foo.js
var socket;
var managing = [];

Storages.alwaysUseJsonInStorage(true);
var db = Storages.localStorage

var margin = { top: 0, right: 60, bottom: 30, left: 0 }
var width = 700 - margin.left - margin.right
var height = 300 - margin.top - margin.bottom

const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']

var parseDate = d3.utcParse("%Y-%m-%d %H:%M:%S%Z")
var dateFormat = d3.timeFormat("%b %e|%I:%M %p")

The uglifyjs CLI command executed or minify() options used.
$ uglifyjs --compress --mangle -- foo.js

JavaScript output or error produced.

Parse error at foo.js:11,0
const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov
^
ERROR: Unexpected token: keyword (const)
    at JS_Parse_Error.get (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:21:1), <anonymous>:79:23)
    at fatal (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:271:52)
    at run (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:228:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:158:5)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

All 4 comments

<!--
    Note: `uglify-js` only supports ES5. 
    Those wishing to minify ES6 should use `uglify-es`.
-->

@kzc I don't understand your comment.

What's ES5/ES6? Am I using ES6? How do I know? I'm just writing some javascript for a web-based app. I'm not very versed in the javascript ecosystem.

https://github.com/mishoo/UglifyJS2/blob/harmony/README.md#install

Try Google or Stackoverflow for javascript terms.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jimbly picture Jimbly  路  4Comments

alexlamsl picture alexlamsl  路  4Comments

lhtdesignde picture lhtdesignde  路  3Comments

PinkyJie picture PinkyJie  路  3Comments

GrosSacASac picture GrosSacASac  路  3Comments