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

new features of Node.js: native fetch #503

Open
Mas0nShi opened this issue Jun 10, 2022 · 6 comments
Open

new features of Node.js: native fetch #503

Mas0nShi opened this issue Jun 10, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@Mas0nShi
Copy link
Contributor

Mas0nShi commented Jun 10, 2022

node add the experimental fetch after v17.5.0, so maybe we can delete package dependency of node-fetch in the near future.

Refer:
https://nodejs.org/en/blog/release/v17.5.0

@capricorn86
Copy link
Owner

I also read about it. It would be nice to use native 🙂 I think we need to wait until it is available in an LTS version.

@capricorn86 capricorn86 added the enhancement New feature or request label Jun 14, 2022
@ypconstante
Copy link

Node 18 LTS started this week and fetch is available without flags, but its classified as experimental

https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch

@Mas0nShi
Copy link
Contributor Author

Nice 🤩

@tatemz
Copy link

tatemz commented Apr 21, 2023

I notice that my tests that use happy-dom fail when I compare Request objects in node 18 but they don't fail in node 16. I'd love to use node 18 and the internal WHATWG exports with happy-dom soon. In the meantime, I am going to update my tests to break down a Request object into the pieces I care about.

@capricorn86
Copy link
Owner

Happy DOM has its own implementation of Request, Response, fetch() etc., as it has dependencies to internal logic of Happy DOM which the native fetch() doesn't have as its not a DOM. For example will Happy DOM set cookies in the document if a response has "Set-Cookie" headers.

@tatemz do you have an example of when it fails?

@friday
Copy link

friday commented Jan 30, 2024

I was able to override it like this:

import { GlobalRegistrator } from "@happy-dom/global-registrator";

const f = fetch;

GlobalRegistrator.register();

window.fetch = f;

This fixed an issue for me with the implemented fetch shim:

image

this.nodeRequest.end();

The issue happens every time using bun test. It also happens for script tags with Bun JS and then this workaround doesn't work.

See the same bug filed on their tracker: oven-sh/bun#8774

(Sorry for not debugging more. I'm already spending time I don't have trying to migrate my tests)

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

No branches or pull requests

5 participants