workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: fetch() does not accept URL objects when testing locally but does when deployed

Open ardislu opened this issue 3 years ago • 1 comments
trafficstars

What version of Wrangler are you using?

2.0.23

What operating system are you using?

Windows

Describe the Bug

  1. Clone the example repo: https://github.com/ardislu/cloudflare-pages-url-test
  2. Run npx wrangler pages dev .
  3. Go to http://localhost:8788/api and see it returns an Invalid URL errror
  4. 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

ardislu avatar Aug 01 '22 03:08 ardislu

Can confirm, I can reproduce this too. This is because of the checked-fetch thing we do

threepointone avatar Aug 01 '22 07:08 threepointone

Is this issue up for grabs??

Kronifer avatar Nov 14 '22 22:11 Kronifer