Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isomorphic fetch returns response with empty stream body #209

Open
y-chandra opened this issue Sep 14, 2023 · 4 comments
Open

Isomorphic fetch returns response with empty stream body #209

y-chandra opened this issue Sep 14, 2023 · 4 comments

Comments

@y-chandra
Copy link

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
Copy link

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

@pBread
Copy link

pBread commented Jan 15, 2024

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
Copy link

nsunga commented Mar 22, 2024

@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
Copy link

pBread commented Mar 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants