webpack-contrib/uglifyjs-webpack-plugin

Unexpected token name «i», expected punc «;»

Closed this issue · 9 comments

Running into issues when using babel and uglifyjs together. Getting this error on compilation:

$ npm run build

> uglifyjs-bug-report@0.0.1 build C:\Projects\uglifyjs-bug-report
> webpack

Hash: 59b8aeb1c10604620688
Version: webpack 3.1.0
Time: 738ms
       Asset    Size  Chunks             Chunk Names
    index.js  138 kB       0  [emitted]  main
index.js.map  164 kB       0  [emitted]  main
   [0] (webpack)/buildin/global.js 509 bytes {0} [built]
   [1] ./src/index.js 197 bytes {0} [built]
   [9] (webpack)/buildin/module.js 517 bytes {0} [built]
    + 7 hidden modules

ERROR in index.js from UglifyJs
Unexpected token name «i», expected punc «;» [./node_modules/isemail/lib/index.js:116,0][index.js:226,13]

Compiling without UglifyJS completes without errors.

The isemail library works standalone, but with the babel trnasformation, UglifyJS throws the error above.

Here is a reproduction repository:
https://github.com/AlesMenzel/uglifyjs-bug-report

Node: 8.1.2
NPM: 5.1.0
Webpack: 3.1.0

What version of UglifyJSPlugin ?

Looking at the webpack repo, the webpack 3.1.0 has "uglifyjs-webpack-plugin": "^0.4.6".

Could you try with npm i -D uglifyjs-webpack-plugin@beta, which uses uglify-es (ES2015+ Minification) to see if that's the cause ?

Yes, running with the "1.0.0-beta.1" seems to fix the issue and there is no error. But the build is twice as long, from ~750ms to ~1250ms.

$ npm run build

> uglifyjs-bug-report@0.0.1 build C:\Projects\uglifyjs-bug-report
> webpack

Hash: 59b8aeb1c10604620688
Version: webpack 3.1.0
Time: 1255ms
   Asset     Size  Chunks             Chunk Names
index.js  39.3 kB       0  [emitted]  main
   [0] (webpack)/buildin/global.js 509 bytes {0} [built]
   [1] ./src/index.js 197 bytes {0} [built]
   [9] (webpack)/buildin/module.js 517 bytes {0} [built]
    + 7 hidden modules

Yes ES5 <=> ES2015+ Minification is slower, so Error vs. --perf I guess 😛
We are working on the perf part here #77 atm.

⚠️ babel transpiled code is especially expensive to minimize, you can alternatively check out babili-webpack-plugin (Babel Minifier) and see if it is faster

For anyone looking at this thread after searching for the error, you're most likely using ES6+ language features in your source without having a compiler configured. Innocent line of code like this for (let i = 0; i... would reproduce the error.

If you're using Preact (don't know if the same applies for React) and experience this error it is probably caused by your imports.
When I imported Component from Preact, I accidentally imported it via import {h, Component} from 'preact/src/preact', which led to this error

It should be import {h, Component} from 'preact' of course

I found this issue today too:

Tracing dependencies for: main
Uglify file: /app/public/assets/main-dist.js
Error: Cannot uglify file: /app/public/assets/main-dist.js. Skipping it. Error is:
SyntaxError: Unexpected token name «of», expected punc «;» (line: 25294, col: 27, pos: 1364286)

Someone had introduced for of into our code base. I was only able to find this out by looking at line 25294 in main-dist.js