question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] UglifyJs only works with ES5

See original GitHub issue

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When adding the UglifyJsPlugin, I get an error like

ERROR in global.js from UglifyJs
Unexpected token: name (resolve) [global.js:1218,8]

where the problem like is like this:

function animationFrame() {
    let resolve = null; // <--------------------------------- RIGHT HERE
    const promise = new _promise2.default(function (r) {
        return resolve = r;
    });
    window.requestAnimationFrame(resolve);
    return promise;
}

If the current behavior is a bug, please provide the steps to reproduce.

This is a bug, because not all loaders convert JavaScript to strictly ES5 (which UglifyJs requires). For example, buble-loader can convert JavaScript code for relatively new browser targets, which results in let and const statements that UglifyJs seems to crash on.

What is the expected behavior?

I should be able to stick buble-loader into my Webpack project, and I should be able to use something like UglifyJsPlugin to minify it.

However, this only works if one uses something like Babel to completely convert to ES5.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

I’m on Webpack 3.4.1.

Look how many people have had this problem: https://github.com/joeeames/WebpackFundamentalsCourse/issues/3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
trusktrcommented, Aug 9, 2017

@damsorian just replace webpack/lib/optimize/UglifyJsPlugin with babili-webpack-plugin. You have to npm i babili-webpack-plugin --save-dev first.

0reactions
ickyrrcommented, Sep 20, 2017

in my case, this answer helped me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR in bundle.js from UglifyJs - javascript - Stack Overflow
Yes, UglifyJS only supports ES5 syntax. You'll need to correctly configure Babel to transform your sources down to ES5 syntax.
Read more >
uglify-js - npm
Documentation for UglifyJS 2.x releases can be found here. uglify-js only supports ECMAScript 5 (ES5). Those wishing to minify ES2015+ (ES6+) ...
Read more >
babel/preset-env
babel/preset-env` is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, ...
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
NOTE: At this stage, only modern browsers will work without errors. ... This project transpiles new features of JavaScript (ES6/ES2015 and so on)...
Read more >
Terser vs. Uglify vs. babel-minify: Comparing JavaScript ...
Let's look at an example to demonstrate how minification works. The code below shows a sample JavaScript code for creating an array and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found