matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

Isomorphic fetch returns response with empty stream body #209

Open y-chandra opened 1 year ago

y-chandra commented 1 year ago

Hi team - After updating to NodeJs 18, we've started to see an issue where making an HTTP request using isomorphic-fetch to a url that returns streamed response returns a response with an empty stream even though the status returned is 200. Sharing the screenshots for the responses on NodeJS < 18 vs NodeJs >=18

Response returned on NodeJS < 18

Screen Shot 2023-09-13 at 4 54 41 PM

Response returned on NodeJs >= 18

Screen Shot 2023-09-13 at 4 56 59 PM
rishavchhajer commented 10 months ago

@y-chandra Hi, I have also encountered the same problem recently, did you find any fix for this ?

pBread commented 8 months ago

I am encountering differences in behavior between isomorphic-fetch and the fetch available in my native node version.

reponse.body.getReader is undefined when I use isomorphic-fetch. It's available when I the native fetch in node version 21

nsunga commented 6 months ago

@pBread Were you able to find an alternative or work-around for this?

Currently using node 18 but turning off node's fetch with --no-experimental-fetch

I did notice that fetch is stable in node 21 - https://nodejs.org/docs/latest-v21.x/api/globals.html#fetch

pBread commented 6 months ago

@nsunga, I was trying to replace this hacky code w/isomorphic-fetch. I ended up just leaving it in place. It seemed to work but it made writing tests a pain.

let isNode = false;
async function initializeFetch() {
  if (typeof window === 'undefined' ||
    typeof globalThis.fetch === 'undefined') {
    const nodeFetch = await import('node-fetch');
    fetch = nodeFetch.default;
    isNode = true;
  } else {
    fetch = globalThis.fetch;
  }
}