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

Support Edge environments #146

Open
lopezjurip opened this issue Jun 9, 2023 · 3 comments
Open

Support Edge environments #146

lopezjurip opened this issue Jun 9, 2023 · 3 comments

Comments

@lopezjurip
Copy link

lopezjurip commented Jun 9, 2023

This project relies on the native "http" / "https" modules from Node.js which are not compatible on Edge environments such as Cloudflare Workers, Next.js Edge Routes / middleware nor AWS Lambda Edge.

I would recommend a version built on top of "fetch" witch is getting a native Node.js implementation.

@mike-engel
Copy link
Collaborator

@lopezjurip Thanks for this issue—I wasn't aware that those edge platforms didn't implement those node modules.

Support for this, while being backwards compatible with the latest LTS, seems a bit tricky. Are you aware of any packages that make http requests that support both native node.js and edge platforms? What does the error look like when using this?

@mkcode
Copy link

mkcode commented Oct 4, 2023

I would also really like to see edge support in this library. I am currently using the web API directly to workaround this.

@mike-engel - fetch is natively supported in all edge runtimes and also natively supported in Node 18 and higher: https://nodejs.org/en/blog/announcements/v18-release-announce#fetch-experimental

It can be polyfilled to older Node versions using this library: https://github.com/node-fetch/node-fetch/tree/main

A native implementation can simply be checked for and polyfilled if not present, like done here: https://github.com/lquixada/cross-fetch/blob/v4.x/src/node-polyfill.js

It looks like this project would need a big overhaul to replace http with fetch, but working in all JS environments is really important future proofing!

@mkcode
Copy link

mkcode commented Oct 4, 2023

And we are now past the EOL for Node 16, so no polyfill needed if you minimally support Node 18 and higher: https://nodejs.dev/en/about/releases/

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

No branches or pull requests

3 participants