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

The global "fetch" module is incompatible with the 'original' global node fetch module. #678

Closed
j-o-r opened this issue Sep 21, 2023 · 0 comments

Comments

@j-o-r
Copy link

j-o-r commented Sep 21, 2023

Expected Behavior

Expecting fetch to be compatible with the original Node.js fetch API.

Actual Behavior

The node-fetch module (https://www.npmjs.com/package/node-fetch) overwrites the global fetch module and is incompatible, causing the following error in all underlying imported modules using fetch.

TypeError: res.body.getReader is not a function

Steps to Reproduce the Problem

import bfetch from 'node-fetch';

// error getReader
async function nodefetchExample() {
  const response = await bfetch('https://google.com');
  const reader = await response.body.getReader();
}

nodefetchExample().catch(error => console.error(error));

// no error in original fetch
async function fetchExample() {
  const response = await fetch('https://google.com');
  const reader = await response.body.getReader();
}

fetchExample().catch(error => console.error(error));

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader

Solution:

Do not replace or overwrite the global fetch module with node-fetch if it is already present.
This will also supports the proposed AbortController #527

Specifications

  • Version: 7.2.3
  • Platform: Node v20.6.1
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

Successfully merging a pull request may close this issue.

2 participants