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

Module require incompatibility of node-fetch starting in 1.1.76 #54

Open
ryprice opened this issue Jul 11, 2023 · 4 comments
Open

Module require incompatibility of node-fetch starting in 1.1.76 #54

ryprice opened this issue Jul 11, 2023 · 4 comments

Comments

@ryprice
Copy link
Contributor

ryprice commented Jul 11, 2023

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.

@otisg
Copy link
Member

otisg commented Jul 11, 2023

@ryprice Thanks for the report, we'll have a look. Are you shipping your logs to Sematext or somewhere else?

@ryprice
Copy link
Contributor Author

ryprice commented Jul 11, 2023

I'm shipping to sematext. Just a small sideproject I'm working on.

@regiluze
Copy link
Contributor

hi @ryprice
we've just released a new version of the library --> https://github.com/sematext/logsene-js/releases/tag/1.1.77
Please, try it out and tell us if the issue has been removed. Thanks :)

@ryprice
Copy link
Contributor Author

ryprice commented Jul 14, 2023

Hey, thanks for the quick turnaround, but unfortunately this didn't fix the problem. Now it just says nodeFetch is not a function. If I have time I'll try to figure out what needs to be done or at least make a distilled repro for you. The issue in my case isn't a conflict with window (In fact my env is node so window.fetch shouldn't be defined. logsene-js works fine in my frontend apps.)

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

No branches or pull requests

3 participants