UglifyJS error because of ES6
NordlingDev opened this issue · comments
Cannot use webpack with UglifyJS, because of error:
ERROR in main.js from UglifyJs
Unexpected token: punc (() [main.js:1,975188]
The code it complains about:
function(module,__webpack_exports__,__webpack_require__) {
"use strict";
const defaults = {
initialize() {}, // <-- This is where it begins
mobile: !0,
change() {},
open() {},
close() {},
search: "strict",
bubble:!0
};
__webpack_exports__.a = defaults;
}
Interesting. Are you using the already minified version in your project or importing the module?
@Robdel12 - I'm importing from NPM. Every other node modules can be bundled together with UglifyJS, just not DropKick.
What version of webpack and uglify? I use uglify to compile the built version
I've tried the builtin UglifyJS in the latest Webpack. I also tried the beta version of latest UglifyJS 3 (which uses Harmony). It got past the error, but instead I have mangling issues which probably relates to how Uglify handles mangling of node_modules folder (mangle: false
seems to ignore node_modules folder).
I am getting this error as well, using DropKick in congregation with roots' Sage 9 beta 4.
ERROR Failed to compile with 1 errors scripts/main_678f8f2f.js from UglifyJs Unexpected token: name (_docListener) [scripts/main_678f8f2f.js:3142,4]
Ah crap. It's because uglify 2.x and below can't handle ES6 classes. So there are two options here:
- Upgrade to uglify 3
- Transpile the DK class before going through uglify (
exclude: /node_modules\/(?!(dropkickjs)\/).*/
)
Honestly neither of those are awesome and I didn't know consuming projects would have to explicitly include this module in their transpilation... Changes will have to be made.
@Robdel12 - I'll stay with a min.js file in the meanwhile. Just to keep things simple. Thank you for getting into it!
@Robdel12 I ended up excluding the dropkick class, should be good as a temp fix. Thanks for the solution!