webpack/loader-utils

@types/loader-utils conflicts with webpack's built-in types

duanlikang opened this issue · 3 comments

Hello,I am not sure if i can give feedback here.

Background Information

When I develop a plugin that uses loader-utils,and the project is base typescript.
The Dependencies:

  "dependencies": {
    "loader-utils": "^2.0.0"
  },
  "devDependencies": {
    "@types/loader-utils": "^2.0.1",
    "webpack": "^5.27.2"
  },

Question

I have some error when I build the project.

node_modules/@types/loader-utils/index.d.ts:11:10 - error TS2305: Module '"../../webpack/types"' has no exported member 'loader'.

11 import { loader } from 'webpack';
            ~~~~~~

node_modules/@types/webpack/index.d.ts:32:3 - error TS2305: Module '"../../tapable/tapable"' has no exported member 'Tapable'.

32   Tapable,
     ~~~~~~~

node_modules/@types/webpack/index.d.ts:1062:23 - error TS2707: Generic type 'SyncWaterfallHook<T, AdditionalOptions>' requires between 1 and 2 type arguments.

1062             resolver: SyncWaterfallHook;

Possible Reason

I find the @types/loader-utils depends @types/webpack.It conflicts with webpack's built-in types.Now, i have to add skipLibCheck:true in my tsconfig.json.I want to know what is the correct way to use that.

loader-utils is deprecated you should not use it, in near future we migrate all loaders and plugins from this and write notes how to migration, don't use it and use webpack types

Thanks for your reply. I got it.
Look forward the future.

putting this in package.json is a good enough work around for me:

    "postinstall": "rm -rf node_modules/@types/loader-utils"