'Why is typescript trying to load the wrong type definitions?

When I try to run typescript on my project I get the following:

# ./node_modules/typescript/bin/tsc --project tsconfig.json 
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;
                           ~~~~~~~~~~~~~~~~~

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

1063             factory: SyncWaterfallHook;
                          ~~~~~~~~~~~~~~~~~

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

1064             beforeResolve: AsyncSeriesWaterfallHook;
                                ~~~~~~~~~~~~~~~~~~~~~~~~

... and so on. 89 errors.

The first line of output suggests it's reading types from ./node_modules/tapable/tapable.d.ts. This types file does not export Tapable; and it exports other types such as AsyncSeriesWaterfallHook with type parameters. So all of this is consistent with the error message.

There's also a file ./node_modules/@types/tapable/index.ts. This does export Tapable. I haven't gone through al the errors, but from the examples I've checked it seems that this types file has exports with the same names but different type parameters, which are consistent with what is declared by webpack.

In other words, the npm module tapable has two conflicting type definition files: one inside its own module and one in the @types/tapable module. Webpack seems to be built for the @types one, but it's trying to validate against the other one.

The package.json for webpack (version 5.24.4) has "tapable": "^2.1.1". tapable has "version": "2.1.1". So they should match.

What's going on? How do I make this compile?



Solution 1:[1]

I had the same problem in a firebase-functions project. I fixed it by giving the tsconfig.json the property "skipLibCheck" with value true.

See more at https://lifesaver.codes/answer/node-modules-tapable-tapable-has-no-exported-member-tapable-12185

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Henry Ecker