michael
michael

Reputation: 2997

How to track down Uglify error with Ember CLI

When I build my Ember CLI app in development, it works fine. When I try to build it for production, Uglify gets upset:

$ ember build --environment=production
version: 1.13.15
Build failed.
File: assets/vendor.js (70503:3)
Unexpected token name «use», expected punc «,»
Error
    at new JS_Parse_Error (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1508:18)
    at js_error (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1516:11)
    at croak (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2008:9)
    at token_error (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2016:9)
    at expect_token (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2029:9)
    at expect (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2032:36)
    at expr_list (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2535:44)
    at subscripts (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2674:30)
    at subscripts (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2651:20)
    at expr_atom (eval at <anonymous> (/Users/michael/Code/queue/node_modules/broccoli-uglify-sourcemap/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2527:20)

I'm at a loss for what this error means - Unexpected token name «use», expected punc «,» - and assets/vendor.js (70503:3) isn't a file I can find anywhere.

If anybody can give me a suggestion of how to track down this error, I'd be really grateful!

Upvotes: 3

Views: 785

Answers (2)

Michael Smyers
Michael Smyers

Reputation: 35

I did some research on this topic, as I too suffered from "something similar".

In my ember project, I use ember-browserify which does the job of copying NPM scripts into vendor.js

It turns out that ember-browserify does not convert ES5/ES6 scripts when doing this copying, and uglify-js (the addon crashing) does not support the ES syntax.

You can see this issue: https://github.com/ef4/ember-browserify/issues/97 and https://github.com/mishoo/UglifyJS2/issues/448

Here is how I resolved the issue (surprisingly easy)

On the terminal: npm install --save-dev ember-browserify babelify babel-preset-es2015

environment.js

browserify: {
  extensions: ['.js'],
  transform: [
    ['babelify', { presets: ["es2015"]}]
  ]
},

Now, when you run ember build --environment=production it will not throw the syntax error.


By the way, a helpful way that I zero'd in on this strange issue is to install uglifyjs globally on command line and ran it manually until I found a reasonable line number to discover the issue with (let vs var).


Keep in mind that ember build will only run on things actually installed in node_modules. While debugging this issue, one gotcha was having different installed versions while doing some trial/error testing.

Upvotes: 2

michael
michael

Reputation: 2997

Running ember init and replacing bower.json and package.json made the error go away.

Upvotes: 1

Related Questions