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

🐛 BUG: `fetch` behaves differently on Cloudflare Pages and local preview

Open tangrufus opened this issue 2 years ago • 1 comments

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

  1. 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
        }))
      }
    }
    
  2. Preview via wrangler pages dev. (Files in ./out folder don't matter)
    npx wrangler pages dev ./out
    
  3. 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)"}
    
  4. Deploy to Cloudflare Pages
  5. 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.

tangrufus avatar Apr 02 '22 05:04 tangrufus

This is an undici bug, which will be fixed when #1520 lands

Skye-31 avatar Aug 05 '22 11:08 Skye-31

I have same issue, how to solve it?

wrangler 2.1.12

wiedymi avatar Oct 19 '22 10:10 wiedymi