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

Prefer native fetch when available #1034

Closed
wants to merge 3 commits into from
Closed

Prefer native fetch when available #1034

wants to merge 3 commits into from

Conversation

GrygrFlzr
Copy link
Member

@GrygrFlzr GrygrFlzr commented Apr 15, 2021

Really not happy with all the ts-ignore directives. Anyway.

Alternative solutions:

Unsolved problems:

  • Use of fetch inside server endpoints - do we want to re-export node-fetch or is this a userland problem?
  • This probably still includes unused node-fetch code in the built output for adapter-cloudflare-workers, which is a waste of space, bandwidth, and potentially cost.

@GrygrFlzr GrygrFlzr marked this pull request as draft April 15, 2021 07:20
@GrygrFlzr GrygrFlzr marked this pull request as ready for review April 15, 2021 07:45
@jacob-8 jacob-8 mentioned this pull request Apr 15, 2021
@Rich-Harris
Copy link
Member

I think this is a fine solution for now, though perhaps we could eliminate the overhead in the case where fetch is already provided by making it part of the adapter? i.e. each adapter is responsible for bringing a fetch implementation if one doesn't already exist.

So adapter-node might add an import in server.js...

import fetch from 'node-fetch';
globalThis.fetch = fetch;

...while cloudflare/deno/whatever would just skip that step entirely.

It does mean solving the problem n times instead of just once, but I think the solution is cleaner, and it means that users don't need to worry about it.

@benmccann
Copy link
Member

FYI, this is why we had to use beta version of node-fetch: #467

@GrygrFlzr
Copy link
Member Author

Created an alternative PR #1066 following Rich's suggestion to move the node-fetch polyfilling into adapters instead.

@Rich-Harris
Copy link
Member

closing this in favour of #1066

@ignatiusmb ignatiusmb deleted the native-fetch branch August 14, 2021 06:14
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 this pull request may close these issues.

adapter-cfw: server-side fetch fails due to dependency on Node's util.types
3 participants