#Providing fetch to Node.js 16 in a library

1 messages · Page 1 of 1 (latest)

pallid rampart
#

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?

pallid rampart
pallid rampart
pallid rampart
#

Thinking about making a dedicated Node.js build now that uses node-fetch.