From 0a9341c115a9a7cc4607ec8332b0291889b4d22f Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Fri, 30 Oct 2026 21:04:13 +0000 Subject: [PATCH] fix(gax): remove node-fetch types and dependency fallbackServiceStub imported a Response type from node-fetch only to type the response of auth.fetch(). Type it as gaxios.GaxiosResponse, which google-auth-library returns, and pass the body to pipeline as a stream/web ReadableStream. Remove node-fetch from google-gax's dependencies. The compiled JavaScript is unchanged apart from a comment. Fixes #7679 --- core/packages/gax/package.json | 1 - core/packages/gax/src/fallbackServiceStub.ts | 15 ++++++++------- pnpm-lock.yaml | 3 --- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/core/packages/gax/package.json b/core/packages/gax/package.json index e6ac5a9c84a..19b798fa660 100644 --- a/core/packages/gax/package.json +++ b/core/packages/gax/package.json @@ -16,7 +16,6 @@ "duplexify": "^4.1.3", "google-auth-library": "^11.3.1", "google-logging-utils": "^2.1.0", - "node-fetch": "^3.3.2", "object-hash": "^3.0.0", "proto3-json-serializer": "^4.1.0", "protobufjs": "^7.5.4", diff --git a/core/packages/gax/src/fallbackServiceStub.ts b/core/packages/gax/src/fallbackServiceStub.ts index cf32e5dad8c..065fd041b18 100644 --- a/core/packages/gax/src/fallbackServiceStub.ts +++ b/core/packages/gax/src/fallbackServiceStub.ts @@ -14,10 +14,6 @@ * limitations under the License. */ -import type {Response as NodeFetchResponse} from 'node-fetch' with { - 'resolution-mode': 'import', -}; - import {AuthClient, GoogleAuth, gaxios} from 'google-auth-library'; import * as serializer from 'proto3-json-serializer'; @@ -27,7 +23,8 @@ import {defaultToObjectOptions} from './fallback'; import {GoogleError} from './googleError'; import {setAttemptHttpMethod} from './observability/TracerHelper'; import {rpcCodeFromHttpStatusCode, Status} from './status'; -import {pipeline, PipelineSource} from 'stream'; +import {pipeline} from 'stream'; +import type {ReadableStream as WebReadableStream} from 'stream/web'; import type {Agent as HttpAgent} from 'http'; import type {Agent as HttpsAgent} from 'https'; @@ -516,7 +513,7 @@ export function generateServiceStub( auth .fetch(url, fetchRequest) - .then((response: Response | NodeFetchResponse) => { + .then((response: gaxios.GaxiosResponse) => { // There is a legacy Apiary configuration that some services // use which allows 204 empty responses on success instead of // a 200 OK. This most commonly is seen in delete RPCs, @@ -529,7 +526,11 @@ export function generateServiceStub( } if (response.ok && rpc.responseStream) { pipeline( - response.body as PipelineSource, + // `GaxiosResponse` is typed as the DOM `Response`, but the body + // is a Node.js Readable when gaxios uses node-fetch and an async + // iterable web ReadableStream when it uses native fetch; either + // is a valid `pipeline` source in Node.js. + response.body as WebReadableStream, streamArrayParser, (err: unknown) => { // A caller that cancelled has already torn this stream down diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1d3f5ab9df..9a2a6842a41 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -410,9 +410,6 @@ importers: google-logging-utils: specifier: ^2.1.0 version: 2.1.0 - node-fetch: - specifier: ^3.3.2 - version: 3.3.2 object-hash: specifier: ^3.0.0 version: 3.0.0