workers-sdk
workers-sdk copied to clipboard
🐛 BUG: fetch() does not accept URL objects when testing locally but does when deployed
trafficstars
What version of Wrangler are you using?
2.0.23
What operating system are you using?
Windows
Describe the Bug
- Clone the example repo: https://github.com/ardislu/cloudflare-pages-url-test
- Run
npx wrangler pages dev . - Go to
http://localhost:8788/apiand see it returns anInvalid URLerrror - Deploy the repo to Cloudflare Pages and see that it's now working as expected. I deployed my example repo to: https://cloudflare-pages-url-test.pages.dev/
I figured out a workaround by manually calling .toString() on the URL object before passing it to fetch:
const exampleUrl = new URL('https://example.com');
await fetch(exampleUrl); // Throws an "Invalid URL" error when testing locally but not when deployed
await fetch(exampleUrl.toString()); // Works both locally and when deployed
Can confirm, I can reproduce this too. This is because of the checked-fetch thing we do
Is this issue up for grabs??