Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Conversation

Copy link

Copilot AI commented May 23, 2025

Issue

When using this library with node-fetch instead of native fetch, it would fail with an error: response.body.getReader is not a function. This is because node-fetch doesn't implement the Web Streams API in the same way as native fetch.

Solution

This PR adds support for both implementations:

  1. It checks if response.body.getReader() is available (native fetch)
  2. If available, it uses the existing implementation with getReader()
  3. If not available, it falls back to a Node.js stream implementation using event listeners

The implementation maintains identical timeout and error handling behaviors between both approaches.

Changes

  • Added a check for response.body.getReader availability
  • Added a new processNodeStream function for node-fetch compatible streams
  • Updated documentation to clarify compatibility with both fetch implementations
  • Added a simple compatibility test

This change enables the library to work with both Node.js 18+ (with native fetch) and older Node.js versions using node-fetch as a fallback without any code changes required by the user.

Fixes #6.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits May 23, 2025 19:21
Co-authored-by: jddev273 <59052623+jddev273@users.noreply.github.com>
Co-authored-by: jddev273 <59052623+jddev273@users.noreply.github.com>
Co-authored-by: jddev273 <59052623+jddev273@users.noreply.github.com>
Copilot AI changed the title [WIP] response.body.getReader is not a function when using node-fetch Fix response.body.getReader compatibility with node-fetch May 23, 2025
Copilot AI requested a review from jddev273 May 23, 2025 19:24
Copilot finished work on behalf of jddev273 May 23, 2025 19:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

response.body.getReader is not a function when using node-fetch

2 participants