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

node 18.x compatibility #275

Closed
epaminond opened this issue May 10, 2022 · 8 comments · Fixed by #278
Closed

node 18.x compatibility #275

epaminond opened this issue May 10, 2022 · 8 comments · Fixed by #278

Comments

@epaminond
Copy link

epaminond commented May 10, 2022

Same code that runs fine on node 16.x (basic mg.messages.create) fails on node 18.x with following error

TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:5575:34)
    at node:internal/deps/undici/undici:5901:42
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8) {
  cause: TypeError: object2 is not iterable
      at action (node:internal/deps/undici/undici:1661:39)
      at action.next (<anonymous>)
      at Object.pull (node:internal/deps/undici/undici:1709:52)
      at ensureIsPromise (node:internal/webstreams/util:172:19)
      at readableStreamDefaultControllerCallPullIfNeeded (node:internal/webstreams/readablestream:1884:5)
      at node:internal/webstreams/readablestream:1974:7
}

node: 18.1.0
mailgun.js: 6.0.1

@epaminond
Copy link
Author

A workaround for this is to run node 18.x with --no-experimental-fetch flag.

@epaminond
Copy link
Author

Seems like this is coming from ky-universal package.

@zacharytyhacz
Copy link
Contributor

I am getting this as well

(node:93936) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
5/14/2022 3:10:10 PM TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:5575:34)
    at node:internal/deps/undici/undici:5901:42
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8) {
  cause: TypeError: object2 is not iterable
      at action (node:internal/deps/undici/undici:1661:39)
      at action.next (<anonymous>)
      at Object.pull (node:internal/deps/undici/undici:1709:52)
      at ensureIsPromise (node:internal/webstreams/util:172:19)
      at readableStreamDefaultControllerCallPullIfNeeded (node:internal/webstreams/readablestream:1884:5)
      at node:internal/webstreams/readablestream:1974:7
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}
  • Node Version: v18.1.0
  • mailgun.js version : ^6.0.1

@zacharytyhacz
Copy link
Contributor

Interesting, I wonder why they don't just use fetch or axios

@sholladay
Copy link

sholladay commented May 15, 2022

Ky maintainer here. I'd be happy to help debug if someone can provide me with an easy and minimal repro environment so I don't want to have to set up a Mailgun API key, etc.

What I can say right now is that if this problem is indeed related to Node 18 and its newly implemented fetch(), then this should be very easy to solve. We can always fallback to node-fetch even if there's no other simple solution.

EDIT: I will spend time on this when Mailgun wants to use Ky again.

@zacharytyhacz
Copy link
Contributor

Ky maintainer here. I'd be happy to help debug if someone can provide me with an easy and minimal repro environment so I don't want to have to set up a Mailgun API key, etc.

What I can say right now is that if this problem is indeed related to Node 18 and its newly implemented fetch(), then this should be very easy to solve. We can always fallback to node-fetch even if there's no other simple solution.

Hello @sholladay - thank you for noticing this issue thread

🙏 🙏 🙏 🙏

Adding support for Node 18.x would be amazing thank you

@olexandr-mazepa
Copy link
Collaborator

olexandr-mazepa commented May 16, 2022

Hello
@epaminond and @zacharytyhacz can you share a code you wrote to reproduce the issue?
Something is different on my machine than on yours and I don't have this error, so let's start with code implementation.

I like the idea of switching to Axios usage instead of ky.
@zacharytyhacz, thank you a lot for the PR. I will need to spend some additional time testing and checking corner cases, but I plan to publish a new major version of SDK by the end of the week.

@sholladay, thank you for your attention on this issue. There is one more issue that you may be interested to take a look at.
#272
The eighteenth version of node.js by default enables experimental global fetch API. I think this is the reason for these issues.

epaminond added a commit to epaminond/mailgun-error-repro that referenced this issue May 16, 2022
epaminond added a commit to epaminond/mailgun-error-repro that referenced this issue May 16, 2022
@epaminond
Copy link
Author

epaminond commented May 16, 2022

@sholladay , you can try this code to reproduce an error: https://github.com/epaminond/mailgun-error-repro
Basically error occurs even if you don't supply correct MAILGUN_API_KEY and MAILGUN_DOMAIN.
Hope this helps!

CC @olexandr-mazepa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants