question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:22

github_iconTop GitHub Comments

1reaction
n1ru4lcommented, Jul 29, 2022
1reaction
ardatancommented, Jul 28, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error loading schema from URL or GraphQL Endpoint #8012
Describe the bug When attempting to run the code generator with a schema ... \node_modules\cross-undici-fetch\dist\create-node-ponyfill.js:130:16) at fetch ...
Read more >
JavaScript runs everywhere, so should your servers - here is ...
A new way to make any Javascript server platform-agnostic. ... thanks to the new Fetch API standard; We've created Ponyfills so it will...
Read more >
cross-undici-fetch | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Files changed (10) - Renovate Bot Package Diff
I did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an...
Read more >
Cross-undici-fetch NPM
My preferred library used to be isomorphic-fetch but it has this bug that prevents it from running in a react native environment. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found