question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use the fetch available in the environment instead of cross-fetch

See original GitHub issue

For cloudflare workers and deno where there is fetch available in the environment already, currently we need initialise the client like this

const supabase = createClient(
    "https://yyy.supabase.co",  "xxx", {
      fetch: fetch.bind(globalThis),
    }
  );

Instead we should use the following algorithm to get fetch

  • Use the custom fetch option when provided
  • Use the global fetch if available
  • else use cross-fetch

With Node implementing the fetch standard soon, fetch is a global we can reasonably assume the existence of in most envionments and only load cross-fetch as a polyfill. cross-fetch also assumes the presence of XMLHttpRequest which leads to a lot of errors.

Client libraries to update

  • storage-js
  • postgrest-js
  • realtime-js (doesn’t use fetch)
  • gotrue-js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iniancommented, Feb 26, 2022

Thanks a lot @soedirgo! 💟 Can you make a final release to supabase-js with these?

Read more comments on GitHub >

github_iconTop Results From Across the Web

cross-fetch - npm
Universal WHATWG Fetch API for Node, Browsers and React Native. ... Start using cross-fetch in your project by running `npm i cross-fetch`.
Read more >
Cross-fetch is not usable in service workers · Issue #78 - GitHub
I'm using this library (via https://github.com/prisma-labs/graphql-request) and it fails to make requests when used within a browser service worker.
Read more >
ReferenceError: fetch is not defined - javascript - Stack Overflow
Show activity on this post. It seems fetch support URL scheme with "http" or "https" for CORS request. Install node fetch library npm...
Read more >
The Fetch API is finally coming to Node.js - LogRocket Blog
The native Fetch API will make HTTP fetching in Node environments feel much smoother and more natural. Cross-platform familiarity. Developers ...
Read more >
Polyfilling the Fetch API for Old Browsers and Node.js
A quick look at polyfilling, along with with solutions for both environments.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found