terser-webpack-plugin: Bug in own typings in 5.2.0

Bug report

Looks like we have a problem in typings.

Actual Behavior

Errors in tsc output

node_modules/terser-webpack-plugin/types/index.d.ts(9,38): error TS2307: Cannot find module 'uglify-js' or its corresponding type declarations.
node_modules/terser-webpack-plugin/types/index.d.ts(10,33): error TS2307: Cannot find module '@swc/core' or its corresponding type declarations.
node_modules/terser-webpack-plugin/types/utils.d.ts(4,44): error TS2307: Cannot find module 'uglify-js' or its corresponding type declarations.
node_modules/terser-webpack-plugin/types/utils.d.ts(5,38): error TS2307: Cannot find module 'uglify-js' or its corresponding type declarations.
node_modules/terser-webpack-plugin/types/utils.d.ts(6,33): error TS2307: Cannot find module '@swc/core' or its corresponding type declarations.

Expected Behavior

No type errors

How Do We Reproduce?

Just try to run node_modules/.bin/tsc in a project with terser-webpack-plugin 5.2.0

Looks like we need to install all possible minifiers. But it looks quite strange. Why do I need to install swc, if I use esbuild?)

My tsconfig is:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "tslib": [
        "./node_modules/tslib/tslib.d.ts"
      ],
      "*": [
        "src/*"
      ]
    },
    "esModuleInterop": true,
    "declaration": false,
    "declarationMap": false,
    "moduleResolution": "node",
    "module": "commonjs",
    "incremental": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "alwaysStrict": true,
    "pretty": false,
    "jsx": "react-jsxdev",
    "strict": true,
    "strictNullChecks": true,
    "target": "es6",
    "noEmitHelpers": true,
    "importHelpers": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strictPropertyInitialization": false,
    "lib": [
      "es6",
      "es2016",
      "es2017",
      "dom"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false
}

The optimization section from my webpack config:

optimization: {
    concatenateModules: true,
    minimizer: [
      new TerserPlugin({
        minify: TerserPlugin.esbuildMinify,
      }),
    ],
  },

As a solution, you can add esbuild, @swc/core and uglify-js typings to dependencies.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 619.85 MB / 16.00 GB
  Binaries:
    Node: 14.17.3 - ~/n/bin/node
    Yarn: 1.22.0 - ~/.yarn/bin/yarn
    npm: 6.14.13 - ~/n/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Firefox: 88.0.1
    Safari: 14.0.1
    Safari Technology Preview: 14.1
  Packages:
    compression-webpack-plugin: 8.0.1 => 8.0.1
    terser-webpack-plugin: 5.2.0 => 5.2.0
    webpack: 5.51.1 => 5.51.1
    webpack-bundle-analyzer: 4.4.2 => 4.4.2
    webpack-cli: 4.8.0 => 4.8.0
    webpack-merge: 5.8.0 => 5.8.0
    webpack-npm-dependencies-analyzer: 1.0.1 => 1.0.1
    webpack-stats-plugin: 1.0.3 => 1.0.3

About this issue

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

Most upvoted comments

We don’t want to install all minimizer because you will get very big node_modules, found workaround - @ts-ignore in our declarations

hm, wait, found one strange, maybe we need report, investigate