apollo-link
apollo-link copied to clipboard
TypeScript 3.6.2 removed GlobalFetch
I am getting errors in apollo-link-http-common when trying to build my code now since GlobalFetch no longer exists.
node_modules/apollo-link-http-common/lib/index.d.ts:38:13 - error TS2304: Cannot find name 'GlobalFetch'.
38 fetch?: GlobalFetch['fetch'];
See the blog post on the update: https://devblogs.microsoft.com/typescript/announcing-typescript-3-6/#dom-updates
My workaround is an additional file ./types/global-fetch.d.ts with "typeRoots": ["./types", "./node_modules/@types"] in tsconfig.json:
declare type GlobalFetch = WindowOrWorkerGlobalScope
This bug is fixed in 04d405a342903274ff67c42dae51a89ee20e72dc but there is still no new version in NPM repo.
I am using apollo-client 2.6.2 in my Ionic application. It was working fine until I ran npm install again. I have started getting the following error in apollo-link:
[app-scripts] [12:45:13] typescript: ......./node_modules/apollo-link-http/lib/httpLink.d.ts, line: 9
[app-scripts] Cannot find name 'GlobalFetch'.
[app-scripts] L8: includeExtensions?: boolean;
[app-scripts] L9: fetch?: GlobalFetch['fetch'];
[app-scripts] L10: headers?: any;
I have been using TypeScript 3.3.333 but suddenly the build has started to fail with the 'GlobalFetch' issue. Can someone help me with a fix or workaround? It has become a showstopper for our application release.
The suggested workaround does not work as in my case.
@satishmolletipipra My guess is you forgot to use "lib": ["dom"],
but you should be able to re-add this type as:
/// <reference lib="dom" />
declare interface GlobalFetch {
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>
}
to your local ./types/ directory.
I am just using TypeScript 3.5 until this gets fixed (as well as some other unrelated issues). I just set this in my package.json: "typescript": "~3.5.2"
I am just using TypeScript 3.5 until this gets fixed (as well as some other unrelated issues). I just set this in my package.json:
"typescript": "~3.5.2"
This seems like the only way right now...
@hwillson any chance to release this fix?
just saw that this fix was released as 1.5.16. So i guess this issue is actually resolved.
To clarify, that's 1.5.16 of apollo-link-http that now depends on the fixed apollo-link-http-common (which had the type error).
Maybe this helps someone as I had problems with applying the workarounds. They didn't work for me probably because I use apollo-boost instead. Also tried yarn resolutions to force fetching of newer nested deps, but it did not help (maybe due to monorepo/nested package structure? didn't investigate fully).
A workaround that did work was to set skipLibCheck: true in tsconfig.json. I didn't like that though and ended up applying a patch with https://www.npmjs.com/package/patch-package:
diff --git a/node_modules/apollo-boost/lib/index.d.ts b/node_modules/apollo-boost/lib/index.d.ts
index 1f58c91..9234caa 100644
--- a/node_modules/apollo-boost/lib/index.d.ts
+++ b/node_modules/apollo-boost/lib/index.d.ts
@@ -22,7 +22,7 @@ export interface PresetConfig {
uri?: string | UriFunction;
credentials?: string;
headers?: any;
- fetch?: GlobalFetch['fetch'];
+ fetch?: WindowOrWorkerGlobalScope['fetch'];
fetchOptions?: HttpLink.Options;
clientState?: ClientStateConfig;
onError?: ErrorLink.ErrorHandler;
diff --git a/node_modules/apollo-boost/src/index.ts b/node_modules/apollo-boost/src/index.ts
index c9f0751..648d1a8 100644
--- a/node_modules/apollo-boost/src/index.ts
+++ b/node_modules/apollo-boost/src/index.ts
@@ -31,7 +31,7 @@ export interface PresetConfig {
uri?: string | UriFunction;
credentials?: string;
headers?: any;
- fetch?: GlobalFetch['fetch'];
+ fetch?: WindowOrWorkerGlobalScope['fetch'];
fetchOptions?: HttpLink.Options;
clientState?: ClientStateConfig;
onError?: ErrorLink.ErrorHandler;
I am still seeing this issue. I can apply a patch as the ^ above mentions, but it makes me kind of nervous. Has this still not been fixed?