From 0fe2f9d2371ba376e1682e240a6cf47a92f137aa Mon Sep 17 00:00:00 2001 From: Louis Bompart Date: Wed, 2 Oct 2024 14:29:25 -0400 Subject: [PATCH] fix: avoid using window in module exports `dist/browser.mjs` is the exported file in `module`. The module can be imported by both NodeJS & browsers alike nowadays and as a library. For example, we recently encountered an issue consuming the library after migrating Headless to an ESM-first package, as we export both ESM for NodeJS & browsers alike. --- bundle/browser-fetch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/browser-fetch.ts b/bundle/browser-fetch.ts index 1dc99fb0..06c0a1ec 100644 --- a/bundle/browser-fetch.ts +++ b/bundle/browser-fetch.ts @@ -1,3 +1,3 @@ // This file is to prevent including a fetch polyfill from the "cross-fetch" dependency when building for a browser target. // Major browsers today provide fetch on the window object, so including a polyfill would needlessly increase the size of the bundle. -export const fetch = window.fetch; +export const fetch = globalThis.fetch;