Skip to content

Best way to conditionally polyfill fetch #1751

Closed Answered by jimmywarting
goldingdamien asked this question in Q&A
Discussion options

You must be logged in to vote

My personal suggestion would just be to tell folks to upgrade their NodeJS version.
Adding this to your package.json

"engine": {
  "node": ">=18"
}

The alternative is that you let the clients bring in their own fetch impl from wherever they choose to bring in. weather it be undici, node-fetch v3 (or v2 for cjs) so you could let them decide for themself what they want to bring in. they might already have a dependency on undici, so it would be unnecessary to add node-fetch into the mix as well.

Does node-fetch automatically handle the conditional loading of fetch? Will node-fetch be used even if fetch already exists?

No, but I have tough about doing that. it would certainly be a breaking …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by goldingdamien
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants