Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

TypeScript 3.6.2 removed GlobalFetch #1131

Open
tyler-johnson opened this issue Aug 28, 2019 · 10 comments
Open

TypeScript 3.6.2 removed GlobalFetch #1131

tyler-johnson opened this issue Aug 28, 2019 · 10 comments

Comments

@tyler-johnson
Copy link

tyler-johnson commented Aug 28, 2019

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

@dex4er
Copy link

dex4er commented Aug 29, 2019

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 04d405a but there is still no new version in NPM repo.

dex4er added a commit to dex4er/ts-node-github-api-example that referenced this issue Aug 29, 2019
 apollo-cache-inmemory                        ^1.6.2  →   ^1.6.3
 apollo-client                                ^2.6.3  →   ^2.6.4
 dotenv                                       ^8.0.0  →   ^8.1.0
 graphql                                     ^14.4.2  →  ^14.5.4
 @graphql-codegen/cli                         ^1.4.0  →   ^1.6.1
 @graphql-codegen/typescript                  ^1.4.0  →   ^1.6.1
 @graphql-codegen/typescript-document-nodes   ^1.4.0  →   ^1.6.1
 @graphql-codegen/typescript-operations       ^1.4.0  →   ^1.6.1
 @types/graphql                              ^14.2.2  →  ^14.5.0
 @types/node                                 ^12.6.2  →  ^12.7.2
 markdownlint-cli                            ^0.17.0  →  ^0.18.0
 tslint                                      ^5.18.0  →  ^5.19.0
 typescript                                   ^3.5.3  →   ^3.6.2
@satishmolletipipra
Copy link

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.

@dex4er
Copy link

dex4er commented Sep 5, 2019

@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.

@tyler-johnson
Copy link
Author

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"

@themaskedavenger
Copy link

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...

@OneCyrus
Copy link

OneCyrus commented Sep 8, 2019

@hwillson any chance to release this fix?

@OneCyrus
Copy link

OneCyrus commented Sep 9, 2019

just saw that this fix was released as 1.5.16. So i guess this issue is actually resolved.

mskri pushed a commit to mskri/ironmon-old that referenced this issue Sep 11, 2019
Compiling to js for production fails due to missing GlobalFetch. According to [this](apollographql/apollo-link#1131) issue fix is done but it's not in released. Solution is either to add type definition or to downgrade.
@seansfkelley
Copy link

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).

@rszalski
Copy link

rszalski commented Dec 9, 2019

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;

@KristenLeach
Copy link

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?

iquabius added a commit to iquabius/olimat that referenced this issue Jun 17, 2020
iquabius added a commit to iquabius/olimat that referenced this issue Jun 17, 2020
* Update dependency typescript to v3.9.5

* Update dependency typescript to v3.9.5

* Fix name clashes in resolvers-types.ts with a hack

I modified indent_style back to "space" in .editorconfig to avoid too
much changes in this commit's diff.

We still have the following problem: "error TS5053: Option 'noEmit'
cannot be specified with option 'composite'."

* Add --composite false to "typecheck:api" npm command

TypeScript incremental build seems to be a problem for projects using
Babel, like Next.js apps:

"error TS5053: Option 'noEmit' cannot be specified with option 'composite'."

So... microsoft/TypeScript#36917

* Suppress TS errors from mocked server context

* Fix *Payload interfaces with a temporary hack

* Fix directories in VS Code workspace config

* Add --composite false to "typecheck:web" npm command

* Add tsconfig.build.json to avoid incremental build

For package/web, which uses Babel.

* Replace GlobalFetch with WindowOrWorkerGlobalScope

GlobalFetch was removed in TS 3.6.2:
apollographql/apollo-link#1131

* Fix root "build" command to use tsconfig.build.json

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Josias Iquabius <iquabius@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants