Definitelytyped: version 13.13 Interface 'Require' incorrectly extends interface 'RequireFunction'.

Created on 18 Apr 2020  路  21Comments  路  Source: DefinitelyTyped/DefinitelyTyped

Issue:
Interface 'Require' incorrectly extends interface 'RequireFunction'.
Types of property 'cache' are incompatible.
Type 'Dict' is not assignable to type '{ [id: string]: NodeModule; }'.
Index signatures are incompatible.
Type 'NodeModule | undefined' is not assignable to type 'NodeModule'.
Type 'undefined' is not assignable to type 'NodeModule'.ts(2430)

Caused by field cache: Dict<NodeModule> (changing to Dict<any> fixes it but not sure that is the accepted solution)

interface Require {
/* tslint:disable-next-line:callable-types /
(id: string): any;
resolve: RequireResolve;
cache: Dict;
/
*
* @deprecated
*/
extensions: RequireExtensions;
main: Module | undefined;
}

Most helpful comment

@thegeekyglass Yes, I deleted the node_modules/@types/node file and "npm install @types/[email protected] --save-dev", amzing it working now. Thank you very much !

All 21 comments

I have the same issue when using React v16.3.1 + TypeScript 3.8.3 in Storybook project.
ERROR in /.../node_modules/@types/node/globals.d.ts(1075,15);

Same issue here with the default template for the Vue CLI Plugin Electron Builder

Same with updating a dependencies in a vue app. TS 3.8.3

By any chance, anyone has had the time to see what type we can use instead of "any" ? I tried changing to Dict but still complains and did not have the time to look deeper into it as i am currently fixing our CI server environment because of this.

My env @types/[email protected] and @types/[email protected].

It seems a repeated declaration .I find the other declaration in file @types\webpack-env\index.d.ts in my node_modules.Where cache is declare as follow:
```... ohter codes ...
cache: {
[id: string]: NodeModule;
}

And it's not  assignable to type `Dict<NodeModule>` in `node_modules\@types\node\globals.d.ts`.
I just changed my code in  `node_modules\@types\node\globals.d.ts` from 

interface Require {
......
cache: Dict; // here
......
}


interface Require {
......
cache: { [id: string]: NodeModule; // here } ...... } ``` and temporarily fix this error . Rollback@types/node` to earlier version seems a better solution.

We could try submitting a pull request with @pkjy suggestion I guess (or we can wait for a bit more feedback first)

Same, using TS 3.8.3 but not Vue.

Same issue when using TS 3.8.3.

Same issue when using TS 3.5.3 and @types/node 13.11.1 in a Vue system

@DeepSeaPenguin2015 I got 13.11.1 to work with vue, make sure your node_modules doesn't contain the lastest version and you don't have it installed globally.

@thegeekyglass my node don't globally, how to make sure node_modules doesn't contain the lastest version, don't understand the words

@DeepSeaPenguin2015, I deleted the whole node_modules folder for the package/project i was working on and ran "npm install" after including "@types/node": "13.11.1" in my dev dependencies. This also worked around the issue when the build was run on a build server (Azure DevOps)

@thegeekyglass Yes, I deleted the node_modules/@types/node file and "npm install @types/[email protected] --save-dev", amzing it working now. Thank you very much !

Ran into this issue as well when updating @types/node. Rolling it back solved the problem.

same issue

@thegeekyglass Yes, I deleted the node_modules/@types/node file and "npm install @types/[email protected] --save-dev", amzing it working now. Thank you very much !

thanks

Can confirm this issue, I have been getting the same issue at seemingly random times working in my Vue.JS projects. The instructions to downgrade to @types/[email protected] worked.

@tdeekens is new version released?

Sorry? Version of what? We pinned our code to an earlier version of the types.

If anyone is still having this issue and finds this thread, for me updating @types/webpack-env fixed the problem

Upgrading to v14.6.0 seems to have resolved this issue for us.

Was this page helpful?
0 / 5 - 0 ratings