Skip to content

Commit 67bffe8

Browse files
fix(backend): Prevent illegal invocation error
Invoking the global.fetch without binding it first to the globalObject fails in Cloudflare Workers with an "Illegal Invocation" error. To fix the issue, we have to bind fetch to the globalThis object. A customer reported this issue using @clerk/remix on Cloudflare Pages. The globalThis object is supported for Node >= 12.0. For more information, refer to supabase/supabase#4417
1 parent 6945ac8 commit 67bffe8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/backend/src/runtime/index.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ type Runtime = {
2222
fetch: typeof global.fetch;
2323
};
2424

25+
// Invoking the global.fetch without binding it first to the globalObject fails in
26+
// Cloudflare Workers with an "Illegal Invocation" error.
27+
//
28+
// The globalThis object is supported for Node >= 12.0.
29+
//
30+
// https://github.com/supabase/supabase/issues/4417
31+
const globalFetch = fetch.bind(globalThis);
32+
2533
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
2634
// For more information refer to https://sinonjs.org/how-to/stub-dependency/
27-
const runtime: Runtime = { crypto, fetch };
35+
const runtime: Runtime = { crypto, fetch: globalFetch };
2836
export default runtime;

0 commit comments

Comments
 (0)