mailgun.js: typeof FormData error at build

Current version is: “mailgun.js”: “^3.2.0”, Getting errors like below:

node_modules/mailgun.js/dist/index.d.ts(5,27): error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
node_modules/mailgun.js/dist/lib/client.d.ts(28,45): error TS2304: Cannot find name 'FormData'.
node_modules/mailgun.js/dist/lib/request.d.ts(8,52): error TS2304: Cannot find name 'FormData'.

The API works fine on local but will not build on production due to error above. When can we expect updates for this?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 21 (5 by maintainers)

Most upvoted comments

I too am running into these three errors. I am attempting to replace mailgun-js with this officially-supported replacement.

"typescript": "^4.1.3"
"ts-node": "^9.1.1"
"form-data": "^4.0.0"
"mailgun.js": "^3.3.0"

It should be noted that the first of the three errors is only different because the FormData function argument is getting interpreted as the the value that it then tries to use as a type. Changing constructor(FormData: new () => FormData); to constructor(formData: new () => FormData); (note lowercase f) results in all three errors being the same:

error TS2304: Cannot find name ‘FormData’.

In other words, typescript is unable to find a FormData global.

temporary workaround

A workaround I am using until it is resolved is to inject my own FormData type override. I have typeRoots setup in my tsconfig, and in the type root directory, I created a file FormData/index.d.ts with the contents

type FormData = unknown;

Although hacky & sad, this allows my project to build without errors.

Any updates on this issue? I’m having the same problem.

Screen Shot 2021-03-11 at 8 08 34 PM

In 8.x version this error still appears image

@andrii-yelis This thread should not be closed as the “fix” doesn’t actually fix the original issue. I am running. mailgun.js: 3.4.0 typescript: 4.3.2

@andrii-yelis this doesn’t fix the original issue as FormData is not defined or imported anywhere. To overcome this you need to define an interface FormData in your type definitions.

@pirtleshell, thanks for the workaround! saved my day!