webpack: UglifyJS breaks with new module syntax

I’m submitting a bug report

Webpack version: 2.1.0-beta.25

Please tell us about your environment: Linux x64

Current behavior: I took a working project using the old module syntax (loaders/loader/query) and replaced it with the new syntax (rules/use/options) and I get the following error: SyntaxError: Unexpected character '’ [main.min.js:5429,52]` Note that replacing the syntax (only those three words) is the ONLY change made. Using the old syntax does not yield this error.

Expected/desired behavior: The bundle would be generated and minified as it is using the old syntax.

  • Language: [ES6/7 | ES5]

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 25 (11 by maintainers)

Most upvoted comments

UglifyJS does not support ES2015+ syntax. You must migrate to the latest version of UglifyJSPlugin in order to minify your code.

First you need to add (or update) the plugin dependency:

npm install -D "uglifyjs-webpack-plugin@^1.1.0"

Then require the plugin:

  const webpack = require("webpack")
+ const UglifyJSPlugin = require("uglifyjs-webpack-plugin")

And update your build configuration:

  plugins: [
-   new webpack.optimize.UglifyJSPlugin({
+   new UglifyJSPlugin({
      sourceMap: true,
-     compress: {
-       warnings: false
+     uglifyOptions: {
+       compress: {
+         warnings: false
+       }
      }
   }),
  ]

Did I provide what you needed? Do you need me to do any other tests?

I have a similar issue with UglifyJs and some postcss plugins … 😦

I don’t know if it has any significance, but as mentioned in my original post the syntax error references a backtick. I am using backticks (ES6 template literals) in a few places, so it might be good to add them to a test.