isomorphic-fetch icon indicating copy to clipboard operation
isomorphic-fetch copied to clipboard

Isomorphic fetch returns response with empty stream body

Open y-chandra opened this issue 1 year ago • 4 comments

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

y-chandra avatar Sep 14 '23 16:09 y-chandra

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

rishavchhajer avatar Dec 04 '23 08:12 rishavchhajer

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

pBread avatar Jan 15 '24 20:01 pBread

@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

nsunga avatar Mar 22 '24 18:03 nsunga

@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;
  }
}

pBread avatar Mar 22 '24 18:03 pBread