Uglifyjs: Warning: Uglification failed. Unexpected token: eof (undefined).

Created on 27 Jul 2014  路  6Comments  路  Source: mishoo/UglifyJS

Hi All,

First of all I'd like to say that I love the plugin, its just great! Good job guys!

The reason why I'm posting this is because I keep getting a Unexpected token error and I can't seem to figure out why. I am using uglifyJS with the grunt-contrib-uglify task but am also getting the error using the command line.

Warning: Uglification failed.
Unexpected token: eof (undefined). 
Line 43 in src/polyfills/array.indexof.js,src/polyfills/document.getElementsByClassName.js,src/init.js,src/methods/ajax.js,src/methods/classes.js,src/methods/custom-eventlisteners.js,src/methods/each.js,src/methods/eventlisteners.js,src/methods/js-each.js,src/methods/obj-methods.js,src/methods/serializeform.js,src/methods/setinterval.js,src/footer.js

I checked line 43 in document.getElementsByClassName.js (which is where the error would occur when parsing right? (it has 29 lines and the array.indexof file has 18) ) and all the other code in the two files but I can't seem to figure out why it's causing errors.

Next to that grunt-contrib-concat runs without any errors and the script itself runs fine in the browser.

Is this a known problem? Do any of you run into the same error?

Most helpful comment

i got the same error and i think i can say wy this happens. some editor add a extra empty line to a file when you save it. but its not just a "break line"... i think its some weird char code... something like "\n\r"... or anything... and this causes UglifyJS2 to crash

All 6 comments

Try running uglifyjs on each file individually. If that works, it's a bug in your grunt concat thing. Otherwise, there's nothing we can really do with the lack of information in this bug report.

i got the same error and i think i can say wy this happens. some editor add a extra empty line to a file when you save it. but its not just a "break line"... i think its some weird char code... something like "\n\r"... or anything... and this causes UglifyJS2 to crash

If either of you could provide us with examples of what is crashing Uglify, that would be great.

Closing this for now.

This happens if you have weird line breaks in one if your files. If you use vim you can run :set fileformat=unix and write to file. This probably happened because you downloaded the original file with a mac-ish program.

This also appears with bad Userscripts/Libraries...Ex. _(Reduced test case without the metadata blocks e.g. this is the whole Userscript library)_

if (true) {
MINIFICATION WARNING (harmony):
  message: Unexpected token: eof (undefined)
  installName: Marti/test_bad_script.js
  line: 2 col: 0 pos: 13

... not a whole lot we can do with it other than don't minify on this particular use case. May help validate the integrity of the source at a later date though. :)


We did however get this in current release via _express-minify_ with:

2016-01-22 12:56:36.806 +00:00: MINIFICATION WARNING (release):
  filename: 0
  message: Unexpected token: eof (undefined)
  line: 15135 col: 14 pos: 524288

_ace-builds_ is the only thing I haven't rechecked out of of our static dep servings and that will take a lot of time to check... but we did have a few dep updates since that date so that could have been another unknown.


Current _ace-builds_ checks okay with CLI.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pvdz picture pvdz  路  3Comments

alexlamsl picture alexlamsl  路  4Comments

alexlamsl picture alexlamsl  路  4Comments

uiteoi picture uiteoi  路  5Comments

chrismanley picture chrismanley  路  5Comments