typscript 4.2.4 multiple errors "error TS2304: Cannot find name 'Request'"
See original GitHub issueI’m working on updating some parts of an API, and tests as part of an API with typescript version 4.
I’m running tsc --noEmit without --skipLibCheck flag, and I see multiple typescript errors in logs.
node_modules/jest-fetch-mock/types/index.d.ts:20:39 - error TS2304: Cannot find name 'Response'.
20 extends jest.MockInstance<Promise<Response>, [string | Request | undefined, RequestInit | undefined]> {
~~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:20:60 - error TS2304: Cannot find name 'Request'.
20 extends jest.MockInstance<Promise<Response>, [string | Request | undefined, RequestInit | undefined]> {
~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:20:81 - error TS2304: Cannot find name 'RequestInit'.
20 extends jest.MockInstance<Promise<Response>, [string | Request | undefined, RequestInit | undefined]> {
~~~~~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:21:23 - error TS2304: Cannot find name 'Request'.
21 (input?: string | Request, init?: RequestInit): Promise<Response>;
~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:21:39 - error TS2304: Cannot find name 'RequestInit'.
21 (input?: string | Request, init?: RequestInit): Promise<Response>;
~~~~~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:21:61 - error TS2304: Cannot find name 'Response'.
21 (input?: string | Request, init?: RequestInit): Promise<Response>;
~~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:44:31 - error TS2304: Cannot find name 'Request'.
44 isMocking(input: string | Request): boolean;
~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:97:57 - error TS2304: Cannot find name 'Request'.
97 export type UrlOrPredicate = string | RegExp | ((input: Request) => boolean);
~~~~~~~
node_modules/jest-fetch-mock/types/index.d.ts:99:50 - error TS2304: Cannot find name 'Request'.
99 export type MockResponseInitFunction = (request: Request) => Promise<MockResponseInit | string>;
~~~~~~~
I have found that this error is possibly related to Request type coming from typescript browser dom library, which is missing in node.js projects, hence causing the missing type.
I found similar issues in github: https://github.com/meilisearch/meilisearch-js/issues/661
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
TypeScript getting error TS2304: cannot find name ' require'
I am getting the error "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page. I have...
Read more >Error TS2304 Cannot find name 'WebGLObject' - Questions
I've done all steps and yes, I installed TypeScript Command and detected it in the babylon.js exporter to script compilation options. I can't...
Read more >TypeScript error TS2304 cannot find name require - Edureka
The error that I'm getting is the "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page....
Read more >Documentation - TypeScript 4.2
TypeScript has a way to declare new names for types called type aliases. ... prefer to get an error message when a dotted...
Read more >error TS2304: Cannot find name 'Message' when using ...
Code: Select all app\primeng-message\primeng-message.component.ts(15,11): error TS2304: Cannot find name 'Message'.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Setting the following in my
tsconfig.jsonfixed it for me.@yinzara Thank you for response! I could say yes to separate tsconfig files, but in case of this project, spec files resides along with ts files they test, and I’m not testing test files, I’m testing whole project with all dependencies, and all of it is backend code for typescript issues with latest ts version. I could --slipLibTest, but in this case I loose ability to see other dependency issues in the project.
import { Request } from "cross-fetch";doesn’t solve it, cos as you’ve confirmed, it does uses “dom” lib under the hood.One more thing - we are not using
cross-fetch, we are usingnode-fetch, so adding one more addiction to node-modules is not optimal, especially counting thatcross-fetchis isomorphic by design, and this is not the case for our application.