Skip to content

Could not find a declaration file for module 'webpack' / 'tapable' #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IlCallo opened this issue Oct 7, 2019 · 6 comments
Closed

Could not find a declaration file for module 'webpack' / 'tapable' #339

IlCallo opened this issue Oct 7, 2019 · 6 comments
Labels

Comments

@IlCallo
Copy link

IlCallo commented Oct 7, 2019

Current behavior

ERROR in /.../node_modules/fork-ts-checker-webpack-plugin/lib/hooks.d.ts(1,26):
TS7016: Could not find a declaration file for module 'webpack'. '/.../node_modules/webpack/lib/webpack.js' implicitly has an 'any' type.
  Try `npm install @types/webpack` if it exists or add a new declaration (.d.ts) file containing `declare module 'webpack';`
ERROR in /.../node_modules/fork-ts-checker-webpack-plugin/lib/hooks.d.ts(2,43):
TS7016: Could not find a declaration file for module 'tapable'. '/.../node_modules/tapable/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/tapable` if it exists or add a new declaration (.d.ts) file containing `declare module 'tapable';`
Version: typescript 3.6.3
Time: 5433ms

Expected behavior

No errors by default, or a peerDependencies warning fired off, or a disclaimer in setup section of the README.

Steps to reproduce the issue

Not really sure, I just updated fork-ts-checker-webpack-plugin to 1.5.0 from 0.5.2 and the error popped up.
The error doesn't show up in 1.3.1 because of the typings dependencies being added, then removed again in 1.3.2.
The problematic declaration seems to be into lib/hooks.d.ts, where webpack and tapable are types are imported.

import * as webpack from 'webpack';
import { AsyncSeriesHook, SyncHook } from 'tapable';
export declare type ForkTsCheckerHooks = 'serviceBeforeStart' | 'cancel' | 'serviceStartError' | 'waiting' | 'serviceStart' | 'receive' | 'serviceOutOfMemory' | 'emit' | 'done';
declare type ForkTsCheckerLegacyHookMap = Record<ForkTsCheckerHooks, string>;
export declare const legacyHookMap: ForkTsCheckerLegacyHookMap;
export declare function getForkTsCheckerWebpackPluginHooks(compiler: webpack.Compiler): Record<ForkTsCheckerHooks, SyncHook<any, any, any> | AsyncSeriesHook<any, any, any>>;
export {};

Manually adding the dependencies fix the errors.

Related:

Environment

  • fork-ts-checker-webpack-plugin: 1.5.0
  • typescript: 3.6.3
  • tslint: N/A
  • eslint: 5.10.0
  • webpack: 4.41.0
  • os: Ubuntu 18.04.3 LTS
@IlCallo IlCallo added the bug label Oct 7, 2019
@johnnyreilly
Copy link
Member

Oh that's a shame. If you'd like to reattempt #281 (I'm not sure how this regressed) I'll certainly take a look at it 🥰

@phryneas
Copy link
Contributor

phryneas commented Oct 7, 2019

In #287 I had moved everything depending on webpack/tapable out to hooks.d.ts in the hopes that only index.d.ts would be included automatically and the rest just where used.

We should definitely not add @types/webpack as a dependency, as as I remember that would re-introduce @types/node as a dependency.

Maybe just move the declaration

export declare type ForkTsCheckerHooks = 'serviceBeforeStart' | 'cancel' | 'serviceStartError' | 'waiting' | 'serviceStart' | 'receive' | 'serviceOutOfMemory' | 'emit' | 'done';

to the index.d.ts, reference it from hooks.ts and make sure hooks.d.ts is removed on build, as it won't contain any more external references?

@IlCallo
Copy link
Author

IlCallo commented Oct 8, 2019

If you'd like to reattempt #281

Not sure about how your typings generation works. If @phryneas already have an idea on it, I'll be happy to check if it works.

I think microsoft/TypeScript#18588 is somewhat related and there could be some workarounds. Still, no official solution

@akleiber
Copy link

hi @phryneas do you have a PR for this that I may not find? Because you mentioned here #342 (comment) that you are working on it - if not is your suggestion solution the way to go?
-> #339 (comment)

@phryneas
Copy link
Contributor

@akleiber Argh, I had experimented using API-extractor for that, hit a roadblock, got distracted and forgot about that. Sorry!
Yes, comment 339 would be the easy way to go about this. Would you want to do a PR on this? I'm a bit swamped right now.

@piotr-oles piotr-oles mentioned this issue Apr 18, 2020
26 tasks
piotr-oles added a commit that referenced this issue May 25, 2020
piotr-oles added a commit that referenced this issue May 25, 2020
Fixes E2E test to ensure that the package typings can be consumed without need to install external packages except `@types/webpack`.

Solves: #339
piotr-oles added a commit that referenced this issue May 26, 2020
Fixes E2E test to ensure that the package typings can be consumed without need to install external packages except `@types/webpack`.

✅ Solves: #339
@piotr-oles
Copy link
Collaborator

Fix released in the 5.0.0-alpha.7 version :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants