Sam Lim
Sam Lim

Reputation: 197

Can't Precompile Rails Assets Due to Uglifier Punc Error

This is the error I receive while checking my application.js from public/assets/js in an online JavaScript Minifier:

Parse error: Unexpected token: punc (})
Line 22315, column 33

22314:     url: "/products/per_amount",
22315:     data: {id: quantity, product},
22316:     dataType: "json",

That simply looks like this:

$.ajax({
url: "/products/per_amount",
data: {id: quantity, product},
dataType: "json",
type: "GET",
...

this is the same error as this but everywhere I looked said it was either fixed or the solution I tried did not work.

Upvotes: 1

Views: 598

Answers (1)

ichigolas
ichigolas

Reputation: 7725

It seems that you are using a feature of ES6 that is not supported by Uglifier: http://es6-features.org/#PropertyShorthand.

I think Uglifier's target is ES5 and won't accept anything but ES5 code. You can do a rapid fix by rewriting your code in ES5:

$.ajax({
url: "/products/per_amount",
data: {id: quantity, product: product},
dataType: "json",
type: "GET",

If you want to retain your syntax goodies look into using Babel to transpile your code into ES5.

Upvotes: 1

Related Questions