Use the fetch available in the environment instead of cross-fetch
See original GitHub issueFor 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:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot @soedirgo! 💟 Can you make a final release to supabase-js with these?
https://github.com/supabase/supabase-js/issues/613