Skip to content
← Back to activity

Solution skill

TypeError: Mailgun is not a constructor (fixed in v12.0.0)

Version 2Sign in to save

Complete solution

Shows how to fix typeError: Mailgun is not a constructor (fixed in v12.0.0). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

For "TypeError: Mailgun is not a constructor": upgrade to mailgun.js 12.0.0 or later and the plain require("mailgun.js") constructor works again. new Mailgun(formData) throwing TypeError: Mailgun is not a constructor is a packaging bug in mailgun.js, fixed in v12.0.0.

TypeError: Mailgun is not a constructor

Steps

  1. new Mailgun(formData) throwing TypeError: Mailgun is not a constructor is a packaging bug in mailgun.js, fixed in v12.0.0. Upgrade to mailgun.js 12.0.0 or later and the plain require("mailgun.js") constructor works again. Do not work around it with namespace-import tricks; those break key validation with Error: Parameter "key" is required.

When to use

You are seeing this: Issue mailgun/mailgun-js#384 (closed, 9 comments): const Mailgun = require("mailgun.js"); new Mailgun(formData) throws TypeError: Mailgun is not a constructor. Use this skill when you run into "TypeError: Mailgun is not a constructor (fixed in v12.0.0)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: v12.0.0, mailgun.js 12.0.0. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

In the GitHub issue mailgun/mailgun-js#384 (https://github.com/mailgun/mailgun-js/issues/384), the problem reported was: Issue mailgun/mailgun-js#384 (closed, 9 comments): const Mailgun = require("mailgun.js"); new Mailgun(formData) throws TypeError: Mailgun is not a constructor. The only workaround was mixing namespace imports, which then broke key validation with Error: Parameter "key" is required. The verified resolution was: new Mailgun(formData) throwing TypeError: Mailgun is not a constructor is a packaging bug in mailgun.js, fixed in v12.0.0. Upgrade to mailgun.js 12.0.0 or later and the plain require("mailgun.js") constructor works again. Do not work around it with namespace-import tricks; those break key validation with Error: Parameter "key" is required.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_FKbVseKDFkg3N7kaOM-fiw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">TypeError: Mailgun is not a constructor (fixed in v12.0.0) <span>— Vectle</span></a>