graphql-yoga: Dependency cross-undici-fetch ponyfill has broken every fetch in my API

Describe the bug

I’ve recently moved to grpahql-yoga, and while it’s been absolutely fantastic, I’ve noticed a key part of my app is completely broken.

Before I was using isomorphic-unfetch to fetch an image url and then transforming it into a blob:

export const createFile = async (url: string): Promise<Blob> => {
  let response;
  try {
    response = await fetch(url);
  } catch (err: any) {
    throw new Error(err);
  }

  const blob = await response?.blob();

  return blob;
};

Since moving to graphql-yoga, any request done with any implementation of a server-side fetch fails:

error - uncaughtException: TypeError: Cannot read properties of undefined (reading 'get')
    at Function.value (/home/leonardo/commentcarp-api/node_modules/cross-undici-fetch/dist/create-node-ponyfill.js:198:26)     
    at new Headers (/home/leonardo/commentcarp-api/node_modules/next/dist/compiled/node-fetch/index.js:1:56447)
    at createHeadersLenient (/home/leonardo/commentcarp-api/node_modules/next/dist/compiled/node-fetch/index.js:1:59685)       
    at ClientRequest.<anonymous> (/home/leonardo/commentcarp-api/node_modules/next/dist/compiled/node-fetch/index.js:1:65909)  
    at ClientRequest.emit (node:events:390:28)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:623:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
    at TLSSocket.socketOnData (node:_http_client:487:22)
    at TLSSocket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

No matter what I install or what I import (tried with node-fetch, isomorphic-unfetch, cross-fetch), the error always mentions cross-undici-fetch/dist/create-node-ponyfill.js.

I think this ponyfill is overriding any fetch request I make, and since it fails my API is completely broken.

Your Example Website or App

https://codesandbox.io/s/silly-einstein-w7jjci?file=/pages/api/index.js You can try the request from here https://w7jjci.sse.codesandbox.io/api?query=query+MyQuery+{ ++status }

Steps to Reproduce the Bug or Issue

  1. Run this request https://w7jjci.sse.codesandbox.io/api?query=query+MyQuery+{ ++status }
  2. Check the console

Expected behavior

Fetch should succeed.

Screenshots or Videos

No response

Platform

  • OS: Linux
  • NodeJS: 16.13.1
  • @graphql-yoga/node: ^2.13.1

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22

Most upvoted comments

https://codesandbox.io/s/youthful-violet-rbigu6?file=/pages/api/index.js Ok now it seems to be working with the canary of #1493 I’ll cut a release soon