question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error when sending a email on v3 - TypeError: Expected signal to be an instanceof AbortSignal

See original GitHub issue
Error when sending email with mailgun: TypeError: Expected signal to be an instanceof AbortSignal
at new Request (app/node_modules/node-fetch/lib/index.js:1222:10)
at new v (app/node_modules/mailgun.js/dist/mailgun.js:2:30777)
at Object.t [as default] (app/node_modules/mailgun.js/dist/mailgun.js:2:34628)
at e.<anonymous> (app/node_modules/mailgun.js/dist/mailgun.js:2:11808)
at app/node_modules/mailgun.js/dist/mailgun.js:2:10637
at Object.next (app/node_modules/mailgun.js/dist/mailgun.js:2:10742)
at app/node_modules/mailgun.js/dist/mailgun.js:2:9654
at new Promise (<anonymous>)
at o (app/node_modules/mailgun.js/dist/mailgun.js:2:9399)
at e.request (app/node_modules/mailgun.js/dist/mailgun.js:2:11368)
at e.command (app/node_modules/mailgun.js/dist/mailgun.js:2:12652)
at e.postMulti (app/node_modules/mailgun.js/dist/mailgun.js:2:13422)
at e.create (app/node_modules/mailgun.js/dist/mailgun.js:2:8669)
import Mailgun from 'mailgun.js';
import formData from 'form-data';

const mailgun = new Mailgun(formData);

  const mg = mailgun.client({
    username: 'api',
    key: config.MAILGUN.MAILGUN_API_KEY,
  });

return await mg.messages.create(domain, message);

this is using node with webpack

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

19reactions
jozsefsallaicommented, Feb 19, 2021

@darrylyoung @ssijak Node.js doesn’t have AbortController by default, and when the request library used by mailgun.js (ky-universal) sees that, it tries to polyfill it using abort-controller. This module will NOT work in a Node.js environment, so we have to polyfill it ourselves using node-abort-controller.

First install the module:

npm install node-abort-controller

Then import and polyfill AbortController before importing mailgun.js, so ky-universal will see it in the global context and won’t try to override it:

import AbortController from 'node-abort-controller';
global.AbortController = AbortController;

import Mailgun from 'mailgun.js';
import formData from 'form-data';

const mailgun = new Mailgun(formData);

const mg = mailgun.client({
  username: 'api',
  domain: process.env.DOMAIN,
  key: process.env.MAILGUN_API_KEY,
  url: 'https://api.eu.mailgun.net',
});

To me, this feels like an upstream compatibility issue with ky-universal, rather than a bug in mailgun.js, but they might want to mention this in their docs until the maintainers of ky-universal do something about it.

4reactions
mustafaKamal-fecommented, Apr 30, 2021

I hope one day ppl at Mailgun hire some one for writting better technical documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

error when sending a email on v3 - TypeError: Expected ...
Error when sending email with mailgun: TypeError: Expected signal to be an instanceof AbortSignal at new Request ...
Read more >
Error with Lambda Function running on NodeJS netlify ...
My function always seems to return an error in development which says Function invocation failed: TypeError: Expected signal to be an instanceof ...
Read more >
[JS Client] Expected signal to be an instanceof AbortSignal
When webpacking in production mode for nodejs an application that uses Ktor JS client with new IR compialtion backend and running it, any...
Read more >
https://unpkg.com/node-fetch@3.0.0-beta.6/dist/ind...
isAbortSignal(signal)) { throw new TypeError('Expected signal to be an instanceof AbortSignal'); } this[INTERNALS$2] = { method, redirect: init.redirect ...
Read more >
TypeError: Expected signal to be an instanceof AbortSignal
My function always seems to return an error in development which says Function invocation failed: TypeError: Expected signal to be an instanceof AbortSignal ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found