lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.66k stars 102 forks source link

TypeError: data.getReader is not a function #165

Closed louis030195 closed 1 year ago

louis030195 commented 1 year ago

Hi, your lib is very helpful, thanks a lot 🙏

I'm facing some issue with the exact code that was working fine using browser fetch when trying to use cross-fetch, this is a snippet of what I'm trying to run:

const response = await fetch(url, {
    method: 'POST',
    headers: headers,
    body: body,
  })

  if (!response.ok) {
    // assuming the error is a JSON object
    const message = await response.json()
    throw new Error(message)
  }

  // This data is a ReadableStream
  const data = response.body
  if (!data) {
    return
  }

  const reader = data.getReader()

Where my API is returning a Response which is a stream

I get a TypeError: data.getReader is not a function

The error disappear when I comment import fetch from "cross-fetch"

Any idea? Should I use a different API with cross-fetch? Any help would be highly appreciated 🔥

louis030195 commented 1 year ago

used https lib instead

samheutmaker commented 1 year ago

@louis030195 what is https lib? Can you provide a link?

louis030195 commented 1 year ago

@samheutmaker sorry this is my workaround now https://github.com/different-ai/embedbase/blob/2973555c3fa3d5aab2dc8e7278fe4b9e0a1e597d/sdk/embedbase-js/src/utils.ts#L135