Closed KyloJorgensen closed 5 years ago
I'm not familiar with Typescript but I think fetch, Request, Response and Headers are supposed to be global types, aren't they?
In my VSCode, there's no such warning.
Closing this since there was no answer.
@lquixada please reopen. I have the same error as @KyloJorgensen. I don't think those are global types. I don't see them defined in the node type definitions at least.
/builds/x/api/node_modules/cross-fetch/index.d.ts (1,27): Cannot find name 'fetch'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (2,27): Cannot find name 'Request'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (3,27): Cannot find name 'Response'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (4,31): Cannot find name 'Headers'. Did you mean 'headers'?
hey @esetnik, can you try going to your tsconfig.json > compilerOptions > libs and add "dom" to the list?
I was seeing the same issue - import fetch from "cross-fetch";
wasn't picking up any types for fetch
, and the index.d.ts
file showed Cannot find name 'fetch'.
Adding dom
to libs
fixed the issue for me. Thanks @lquixada!
I don't think dom
should be added to libs
for node environments. This adds a lot of types that are only available in the browser.
@esetnik you're right! however, if you follow the the fetch, Request, Response and Header declaration inside the lib.dom.d.ts, you'll realize that those are very deeply nested declarations. Unfortunately, there's no easy way to extract and maintain them. It would be needed a lot of copy and paste and it would be hard to keep track of any update.
In my opinion, having a single source of truth (the lib.dom.d.ts in this case) is more valuable than saving a few kilobytes that users would not have to download anyway.
usesing vscode to write nodejs server code