I maintain an npm package that needs to make HTTP requests. Previously I've been using a dynamic import to node-fetch if globalThis.fetch is not present.
With Vite 4.3 users see the warning introduced in https://github.com/vitejs/vite/commit/72050f9 when they use this library. Is there a recommended strategy to provide fetch to Node.js 16 and 17 which don't have it, while not bundling this dependency for the browser?
#Providing fetch to Node.js 16 in a library
1 messages · Page 1 of 1 (latest)
In their Next.js package Clerk
uses subpath imports - is this something I can rely on most bunders to understand?
https://nodejs.org/api/packages.html#subpath-imports
https://github.com/clerkinc/javascript/blob/58a3db6e8371a570da5ed9e306535c379d0e314d/packages/backend/package.json#L17
I'm considering https://www.builder.io/blog/stop-polyfilling-fetch-in-your-npm-package but this would be a significant change.
Builder.io
With the rapidly evolving state of JavaScript, it's important to understand how to provide support for the fetch API in Node environments. Recently, we had to address this issue for our Builder.io SDKs, and in this post, we’ll share our perspective on the matter to help other developers.
Thinking about making a dedicated Node.js build now that uses node-fetch.