UglifyJS throws unexpected token: keyword (const) with node_modules

后端 未结 7 1890
清歌不尽
清歌不尽 2020-12-13 16:31

A small project I started make use a node module (installed via npm) that declares const variables. Running and testing this project is well, b

7条回答
  •  生来不讨喜
    2020-12-13 17:31

    UglifyJS does not support es6. const is an es6 declaration, so it throws an error.

    What is weird is that the package you use does not transpile its files to es5 to be used anywhere.

    If you want to still use UglifyJS (to re-use the configuration for example) use the ES6+ compatible version, uglify-es. (Warning: uglify-es is now abandoned.)

    And as Ser mentionned, you should now use terser-webpack-plugin.

提交回复
热议问题