-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Error when doing external fetch on Cloudflare Workers #6739
Comments
It looks like cloudflare does not support everything on RequestInit, here's what they have https://developers.cloudflare.com/workers//runtime-apis/request#requestinit mode and credentials are not on it |
Just accessing credentials (or mode i guess) throws an error, so even |
only workaround i found so far is reverting to 1.0.0-next.469 which is the release before #6565 was introduced (next.470). |
Adding an handleFetch in ....
export async function handleFetch({ request, fetch }) {
// FIXES: https://github.com/sveltejs/kit/issues/6739
const rekuest = {
get(target: Request, prop: string) {
if (['credentials', 'mode'].includes(prop)) {
return '¯¯\\_(ツ)_//¯¯';
}
return target[prop];
}
};
return fetch(new Proxy(request, rekuest));
} PS: |
@denizkenan This workaround doesn't seem to work on Cloudflare Workers, the runtime |
This is particularly hideous if you want to access a
I'm not aware of any workaround, except downgrading / patching SvelteKit :-( EDIT: This sucks extra for me personally, because I already have code depending on |
Cloudflare Workers `Request` object is non-standard and has properties `mode` and `credentials` that throw exceptions if accessed. Its constructor also refuses to accept explicit values for those. The spec for `Request` pretty clearly states defaults are mode="cors" and credentials="same-origin": https://fetch.spec.whatwg.org/#request-class Use the knowledge that Cloudflare Workers `Request` has a property `cf`, and avoid accessing the boobytrapped properties when running in Cloudflare. See sveltejs#6739
I made a quick workaround for this. Here's the tl;dr: - request.credentials !== 'omit'
+ ('cf' in request ? 'same-origin' : request.credentials) !== 'omit' npm i 'https://gitpkg.now.sh/tripoutside/sveltekit-cloudflare-workaround-issue6739/packages/kit?2dcb3e3cc0c2178850e617ff5595d8042d91a408' (Jump through hoops due to npm/npm#2974 and github tarballs always starting from root.) |
My workaround was similar to @denizkenan - add
This works when publishing via wrangler, but not when using Pages' GitHub integration to have Cloudflare perform the build. This is using a different adapter, which I suspect explains the difference. |
I've tried this and it does indeed work when using wrangler (miniflare) to run it locally. However it still errors when deployed to Cloudflare Pages, even when using wrangler. |
Seems to be a re-emergence of this bug: sveltejs/kit#6739 TODO: Remove this when it's been re-patched
Describe the bug
Since #6565 doing external fetch in a load function will fail with
Failed to get the 'mode' property on 'Request'
on Cloudflare Workers.Reproduction
The simplest reproduction is simply having a load function like this
A full project here: https://github.com/xforce/sveltekit-cloudflare-error
This requires are cloudflare account with workers enabled.
run:
npm run build && npx wrangler publish
.Logs
Severity
blocking an upgrade
Additional Information
This appears to come from this line
kit/packages/kit/src/runtime/server/page/fetch.js
Line 90 in 4922e26
The text was updated successfully, but these errors were encountered: