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

TypeError: Mailgun is not a constructor #384

Open
bhkangw opened this issue Sep 7, 2023 · 6 comments
Open

TypeError: Mailgun is not a constructor #384

bhkangw opened this issue Sep 7, 2023 · 6 comments

Comments

@bhkangw
Copy link

bhkangw commented Sep 7, 2023

Getting Unhandled Runtime Error below.. TypeError: Mailgun is not a constructor

const formData = require("form-data");
const Mailgun = require("mailgun.js");
const mailgun = new Mailgun(formData);

const mg = mailgun.client({
	username: "api",
	key: process.env.MAILGUN_API_KEY,
});

Only way I've been able to bypass is writing imports like this, but then it requires my key or else gives Error: Parameter "key" is required

import * as FormData from "form-data";
import Mailgun from "mailgun.js";
const mailgun = new Mailgun(FormData);

const mg = mailgun.client({ 
	username: "api", 
	key: process.env.MAILGUN_API_KEY || "mykeyhere"
});
@olexandr-mazepa
Copy link
Collaborator

Hi @bhkangw
Can you add more details about environment and versions of dependencies you use?
The second case is really weird just because there is a simple check behind.
https://github.com/mailgun/mailgun.js/blob/970c9b66e067cb39d307b2b771bc7ae6f2a5fd2b/lib/Classes/MailgunClient.ts#L64C5-L66C6

@bhkangw
Copy link
Author

bhkangw commented Sep 14, 2023

@olexandr-mazepa thanks for the reply, here is my package.json

{
  "name": "",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@vercel/analytics": "^1.0.2",
    "axios": "^1.5.0",
    "eslint": "8.47.0",
    "eslint-config-next": "13.4.19",
    "form-data": "^4.0.0",
    "mailgun.js": "^9.2.1",
    "micro": "^10.0.1",
    "mongodb": "^6.0.0",
    "mongoose": "^7.5.0",
    "next": "13.4.19",
    "nodemailer": "^6.9.5",
    "prettier": "^3.0.2",
    "prop-types": "^15.8.1",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@types/node": "20.5.3",
    "@types/react": "18.2.21",
    "autoprefixer": "^10.4.15",
    "daisyui": "^3.5.1",
    "postcss": "^8.4.28",
    "tailwindcss": "^3.3.3"
  }
}

@marclou
Copy link

marclou commented Oct 21, 2023

Same here

@olexandr-mazepa
Copy link
Collaborator

Hi @bhkangw @marclou
A couple of times I've tried to reproduce this, but unfortunately without any luck.
Can somebody share with me a minimum reproducible example for this?

@life-efficient
Copy link

Seems to be fixed by using import Mailgun from "mailgun.js" rather than const Mailgun = require("mailgun.js")

@medv
Copy link

medv commented Nov 6, 2024

under esm + nodenext:

import Mailgun from 'mailgun.js'

new Mailgun.default(FormData)

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

5 participants