workers-sdk
workers-sdk copied to clipboard
🐛 BUG: `fetch` behaves differently on Cloudflare Pages and local preview
What version of Wrangler
are you using?
0.0.24
What operating system are you using?
Mac
Describe the Bug
fetch
behaves differently on Cloudflare Pages and local preview (wrangler pages dev
).
Steps to reproduce
- Create
functions/demo.js
// functions/demo.js export const onRequestGet = async () => { try { await fetch('https://wordpress.org/') return new Response('Fetch finished') } catch (err) { return new Response(JSON.stringify({ name: err.name, message: err.message, cause: err.cause, stack: err.stack })) } }
- Preview via
wrangler pages dev
. (Files in./out
folder don't matter)npx wrangler pages dev ./out
- Get the
/demo
page from local preview$ curl http://localhost:8788/demo {"name":"TypeError","message":"fetch failed","cause":{"code":"ERR_INVALID_CHAR"},"stack":"TypeError: fetch failed\n at Object.processResponse (/Users/me/Code/my-demo/node_modules/undici/lib/fetch/index.js:183:23)\n at Fetch.fetchFinale (/Users/me/Code/my-demo/node_modules/undici/lib/fetch/index.js:937:17)\n at Fetch.mainFetch (/Users/me/Code/my-demo/node_modules/undici/lib/fetch/index.js:744:17)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
- Deploy to Cloudflare Pages
- Get the
/demo
page from Cloudflare Pages$ curl https://xxx.my-page.pages.dev/demo Fetch finished
Expected Behaviour
Steps 3 and 5 yield the same result.
This is an undici bug, which will be fixed when #1520 lands
I have same issue, how to solve it?
wrangler 2.1.12