Skip to content
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

'fetch' method is broken with cloudflare dev #5109

Closed
OttoHatt opened this issue May 29, 2022 · 0 comments · Fixed by #5116
Closed

'fetch' method is broken with cloudflare dev #5109

OttoHatt opened this issue May 29, 2022 · 0 comments · Fixed by #5116

Comments

@OttoHatt
Copy link
Contributor

OttoHatt commented May 29, 2022

Describe the bug

Problem

This bug causes any use of the fetch method (the one provided in a route's load callback) to error. (No matter if the request is valid, invalid, local, external, etc.) when running the project locally with Wrangler 2.

It's caused by this issue and this commit. The package Wrangler 2 uses for requests in its local emulator (Undici) expects the credentials header on a request to be non-null, even though the real runtime doesn't mind. This throws an error, cancelling the request. This is making development frustrating as I can't run my app locally at all.

At the time this hack was added, the workers runtime didn't support the credentials header set on a request - this looks to be support now. After removing the removing the credentials: undefined override on this line, the issue is fixed. I can confirm it's now working on Wrangler 1, 2, and the 'real' workers runtime in the cloud!

Fix

// 'Credentials undefined' error.
new Request(new URL(requested, event.url).href, { ...opts, credentials: undefined }),
// Fix
new Request(new URL(requested, event.url).href, { ...opts }),

Reproduction

I've made a tiny repo that demonstrates the problem.

git clone https://github.com/OttoHatt/sveltekit-broken-fetch
cd sveltekit-broken-fetch/
npm i
npm run build
npm run demo

Logs

TypeError: Failed to construct 'Request': The provided value 'undefined' is not a valid enum value of type RequestCredentials.
    at new Request (C:\Users\......\Downloads\sveltekit-broken-fetch\node_modules\undici\lib\fetch\request.js:288:15)
    at new Request (C:\Users\......\Downloads\sveltekit-broken-fetch\node_modules\@miniflare\core\src\standards\http.ts:407:13)
    at Object.construct (C:\Users\......\Downloads\sveltekit-broken-fetch\node_modules\@miniflare\core\src\plugins\core.ts:69:29)
    at fetch (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:1751:36)
    at load2 (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:218:31)
    at load_node (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:1839:32)
    at respond$1 (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:2078:20)
    at resolve (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:2417:105)
    at respond (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:2373:22)
    at Object.fetch (C:\Users\......\Downloads\sveltekit-broken-fetch\.svelte-kit\cloudflare\_worker.js:2657:15)

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
    Memory: 15.90 GB / 31.91 GB
  Binaries:
    Node: 16.14.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 101.0.4951.67
    Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.53)
  npmPackages:
    @sveltejs/adapter-cloudflare: ^1.0.0-next.21 => 1.0.0-next.21
    @sveltejs/kit: next => 1.0.0-next.345
    svelte: ^3.44.0 => 3.48.0

Severity

serious, but I can work around it

Additional Information

No response

Rich-Harris added a commit that referenced this issue May 30, 2022
…5116)

* [fix] remove hack breaking 'fetch' with Undici / CF Wrangler (#5109)

* Create perfect-kiwis-sneeze.md

Co-authored-by: Rich Harris <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant