-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue with fetch while using adapter-cloudflare-workers #1674
Comments
I haven't used Cloudflare workers, so am not sure. Perhaps @halfnelson would know more. I think the issue I'd be most worried about is getting packages that expect things like
The options are set on a per-adapter basis. Right now they're hardcoded, but I would imagine that the
|
Thanks @benmccann. I understand the need for keeping the platform value constant. I too am new with cloudflare and would love to hear from @halfnelson about his thoughts. What I have learned so far is that polyfills such as Again @halfnelson may be a better person to clarify this understanding. |
The original version didn't do any bundling and relied on cloudflare to do the webpack build. Although I am not sure what impacts changing esbuild platform from node -> browser would have, I am not sure browser is the right choice. Cloudflare themselves are trying to support a more "node" like environment while having browser as the default could drag in modules assuming the presence of window, document etc. There is a third option called "neutral" although I am not sure that helps |
looking at it, cross-fetch should import the global fetch, but it looks like it has been temporarily disabled: |
related issues on their repo |
Thanks @halfnelson. lquixada/cross-fetch#78 occurs when cross-fetch picks up browser based build Like what is done in lquixada/cross-fetch#69, even if I override "cross-fetch", I start facing issues with other browser native object/classes such as I get your concern related to window and document object. But with node, similar issues occurs with built-in node modules such as platform=neutral seems to build As per their doc, |
This fixed it for me: {
fetch: (...args) => fetch(...args),
} Source: supabase/postgrest-js#235 |
Closing since there's a viable workaround. Hopefully libraries will stop bundling things like |
Describe the bug
I am using supabase-js with sveltekit and cloudflare-workers. While using adapter-cloudflare-workers, I get hit with following issue when I do
wrangler dev
.This issue happens because
supabase-js
is using cross-fetch as its fetch-polyfill. I found a workaround by applying following patchesnode
tobrowser
in the esbuild options inside adapter-cloudflare-worker.node may have been chosen as a platform of choice for esbuild, since cloudflare has started supporting node libraries for its workers platform.
However, cloudflare provides a hybrid of browser(service-worker) and node environment with native fetch support. Hence, if I keep node as a platform, then I face issues with browser's native object such as fetch, websocket that are also available under cloudflare's service-worker environment.
I have couple of questions here
node
tobrowser
. This will essentially conform to intrinsic nature of service-worker environment supporting many of the browser's native objects.Logs
I have provided the error logs in my issue above
To Reproduce
Here's a sample repo.
supabase url + apikey and cloudflare account_id + zone_id will be required to reproduce issue
Expected behavior
cloudflare-worker adapter should allow options to customise esbuild so that third party libraries using cross-fetch can be integrated to cloudflare environment.
Stacktraces
If you have a stack trace to include, we recommend putting inside a
<details>
block for the sake of the thread's readability:Stack trace
Information about your SvelteKit Installation:
Diagnostics
Severity
This is hampering me from running supabase together with sveltekit on cloudflare. I believe that this issues goes beyond supabase. If not supabase, many other libraries use cross-fetch to access their apis. Hence, they may potentially face this issue.
Additional context
The text was updated successfully, but these errors were encountered: