-
Notifications
You must be signed in to change notification settings - Fork 9
Description
During a recently update from 1.1.75 -> 1.1.76, my service started erroring at runtime with this message:
TypeError: fetch is not a function
at Logsene.send (/path/to/build/service.js:112653:3)
at Timeout._onTimeout (/path/to/build/service.js:112351:12)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
This build uses typescript and webpack. I poked around the transpiled output, console logged fetch, and found that the imported value of fetch from node-fetch was actually a module, not a fetch function. It looked something like: {FetchErrors, Headers, Request, Response, default}. So it seems somewhere there's a mismatch about the style of module (commonjs, esm, etc).
If it's of interest the transpiled line looked like this:
const fetch = __webpack_require__(/*! node-fetch */ "./node_modules/node-fetch/lib/index.mjs")
I'm not the most well versed in the different types of module bundling so I'm not sure what the fix here is, or if it's an issue in my build or in logsene-js configs. I should also note I have another library gaxios that also depends on node-fetch and it does not have any issues. The difference seems to be that gaxios has compiled lib files bundled with it.
Thanks for your help.