webpack-contrib / terser-webpack-plugin

Terser Plugin
MIT License
1.95k stars 157 forks source link

Webpack config: After TypeScript type checking 6 errors appears. #599

Closed dark-kitt closed 6 months ago

dark-kitt commented 7 months ago

Bug report

I wrote my Webpack config in TypeScript. After I was calling vue-tsc 6 terser plugin errors appears.

Actual Behavior

6 Erros

Expected Behavior

0 Erros

How Do We Reproduce?

That is the part of my Webpack configuration, which throws the only 6 errors I have. https://github.com/dark-kitt/wordpress-theme-vue/blob/main/configs/webpack.optimization.ts

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

  System:
    OS: macOS 13.6.6
    CPU: (8) arm64 Apple M2
    Memory: 51.20 MB / 8.00 GB
  Binaries:
    Node: 18.20.1 - ~/.nvm/versions/node/v18.20.1/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.1/bin/npm
  Browsers:
    Chrome: 124.0.6367.91
    Safari: 17.4.1
  Packages:
    babel-loader: ^9.1.3 => 9.1.3 
    css-loader: ^7.0.0 => 7.1.1 
    css-minimizer-webpack-plugin: ^6.0.0 => 6.0.0 
    postcss-loader: ^8.1.1 => 8.1.1 
    purgecss-webpack-plugin: ^6.0.0 => 6.0.0 
    sass-loader: ^14.1.1 => 14.2.1 
    terser-webpack-plugin: ^5.3.10 => 5.3.10 
    ts-loader: ^9.5.1 => 9.5.1 
    vue-loader: ^17.4.2 => 17.4.2 
    webpack: ^5.91.0 => 5.91.0 
    webpack-assets-manifest: ^5.2.1 => 5.2.1 
    webpack-cli: ^5.1.4 => 5.1.4 

Current errors

yarn run v1.22.21
$ vue-tsc --declaration --emitDeclarationOnly
node_modules/terser-webpack-plugin/types/index.d.ts:5:39 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

5 declare class TerserPlugin<T = import("terser").MinifyOptions> {
                                        ~~~~~~~~

node_modules/terser-webpack-plugin/types/index.d.ts:184:17 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

184   ecma?: import("terser").ECMA | undefined;
                    ~~~~~~~~

node_modules/terser-webpack-plugin/types/utils.d.ts:3:42 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

3 export type TerserFormatOptions = import("terser").FormatOptions;
                                           ~~~~~~~~

node_modules/terser-webpack-plugin/types/utils.d.ts:4:36 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

4 export type TerserOptions = import("terser").MinifyOptions;
                                     ~~~~~~~~

node_modules/terser-webpack-plugin/types/utils.d.ts:5:44 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

5 export type TerserCompressOptions = import("terser").CompressOptions;
                                             ~~~~~~~~

node_modules/terser-webpack-plugin/types/utils.d.ts:6:33 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("terser")' call instead.

6 export type TerserECMA = import("terser").ECMA;
                                  ~~~~~~~~

Found 6 errors in 2 files.

Errors  Files
     2  node_modules/terser-webpack-plugin/types/index.d.ts:5
     4  node_modules/terser-webpack-plugin/types/utils.d.ts:3
error Command failed with exit code 2.
alexander-akait commented 6 months ago

Please open an issue in vue-tsc repo, thank you