diff --git a/.changeset/chilled-forks-accept.md b/.changeset/chilled-forks-accept.md new file mode 100644 index 00000000000..473c92cdda5 --- /dev/null +++ b/.changeset/chilled-forks-accept.md @@ -0,0 +1,5 @@ +--- +"@firebase/storage": patch +--- + +Fixed issue where clients using Node.js v18 would use the native `Blob` object which is incompatible with `node-fetch` diff --git a/packages/storage/src/implementation/type.ts b/packages/storage/src/implementation/type.ts index 7d5bc0e19e5..33fb7bb227d 100644 --- a/packages/storage/src/implementation/type.ts +++ b/packages/storage/src/implementation/type.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { isNode } from '@firebase/util'; import { invalidArgument } from './error'; export function isJustDef(p: T | null | undefined): p is T | null { @@ -39,7 +40,9 @@ export function isNativeBlob(p: unknown): p is Blob { } export function isNativeBlobDefined(): boolean { - return typeof Blob !== 'undefined'; + // Note: The `isNode()` check can be removed when `node-fetch` adds native Blob support + // PR: https://github.com/node-fetch/node-fetch/pull/1664 + return typeof Blob !== 'undefined' && !isNode(); } export function validateNumber( diff --git a/packages/storage/test/unit/task.test.ts b/packages/storage/test/unit/task.test.ts index 6b796cc5c86..18da6d83800 100644 --- a/packages/storage/test/unit/task.test.ts +++ b/packages/storage/test/unit/task.test.ts @@ -505,6 +505,7 @@ describe('Firebase Storage > Upload Task', () => { // Function that notifies when we are in the middle of an exponential backoff const readyToCancel = new Promise(resolve => { + // @ts-ignore The types for `stub.callsFake` is incompatible with types of `clock.setTimeout` stub.callsFake((fn, timeout) => { // @ts-ignore The types for `stub.callsFake` is incompatible with types of `clock.setTimeout` const res = fakeSetTimeout(fn, timeout);