Something, somewhere in our code or third-party libraries or who-knows-where, is making uglifyJS unhappy – “ember build --environment production” fails with:
Build failed.
Unexpected token: eof (undefined)
Error
at new JS_Parse_Error (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:189:18)
at js_error (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:197:11)
at croak (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:657:9)
at token_error (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:665:9)
at unexpected (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:671:9)
at block_ (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:977:28)
at ctor.body (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:951:25)
at function_ (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:956:15)
at expr_atom (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:1159:24)
at maybe_unary (/Users/daniel/SourceHG/myproject/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:1328:19)
How do I go about finding out where the problem actually is? It builds okay in our CI environment, but if I do the same steps locally (fresh clone of the code, fresh npm install/bower install), it fails like this, and the error message tells me nothing about where I need to look to work out what is making uglify die.
Answering myself – in node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/index.js, in UglifyWriter.prototype.processFile, add logging on ‘inFile’ to tell me which file it’s processing, and from there I can work out what’s going on. (in particular, uglifyjs doesn’t like jquery/src/intro.js, which is reasonable as that’s not actually a valid file on its own – so I should be making sure our tree doesn’t accidentally hit non-built versions of jquery)
@djmitchella How did you achieve the solution mentioned here.
I am also getting similar error
Build failed.
Unexpected character '`'
Error
at new JS_Parse_Error (/Users/dilip/Documents/Code/Portkey/node_modules/ember-cli-uglify/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/lib/parse.js:196:18)
I’m having the same problem and I’ve spent over 15H trying to fix it to no avail. I isolated it to the ember-cli-ion-rangeslider addon (or so I think), but the version I’m using works for me on a non-fresh install. Only on a fresh install it fails. I can’t identify why. I’ve tried using @djmitchella tip with inFile logging, but it just write vendor.js, which isn’t useful since it’s a few MB file inside the tmp folders.
it’s character 65279 that’s blowing up the parser. That feels like the 0xFE 0xFF BOM; searching for that, it appears in vendor.js at:
; // Ion.RangeSlider
(except that the space between ; and // is actually this character). I fixed this in Webstorm by opening slider-test/bower_components/ionrangeslider/js/ion.rangeSlider.js and doing “remove BOM” – depending on what text editor you’re using you may need to do this differently.
Once I’d removed the BOM from that file (and removed dist/ and tmp/), ember build --environment=production works for me.