Search code examples
javascriptwebpackbundlerminify

Webpack 5 Terser: How can I require 'uglify-module'


I'm trying to use TerserPlugin to minify my code, I found this snippet below in their official docs:

optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          myCustomOption: true,
        },
        minify: (file, sourceMap, minimizerOptions) => {
          const extractedComments = [];
          const { map, code } = require("uglify-module").minify(file, {});
          return { map, code, extractedComments };
        },
      }),
    ],
  }

but after adding this snippet I'm getting an error: Error: Cannot find module 'uglify-module'

also, this 'uglify-module' can't be found on npm registry.

enter image description here


Solution

  • You should use uglify-js instead of uglify-module