mailgun / mailgun.js

Javascript SDK for Mailgun
https://www.npmjs.com/package/mailgun.js
Apache License 2.0
515 stars 109 forks source link

DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead. #412

Closed jarimustonen closed 3 weeks ago

jarimustonen commented 3 months ago

Sending email with Mailgun spams the log files with the following warnings:

(node:6376) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.
    at FormData.append (/Users/jari/Sources/okv-homepage/node_modules/form-data/lib/form_data.js:64:12)
    at addValueBasedOnFD (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/common/FormDataBuilder.ts:196:28)
    at e.addCommonPropertyToFD (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/common/FormDataBuilder.ts:215:7)
    at reduce (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/common/FormDataBuilder.ts:58:14)
    at Array.reduce (<anonymous>)
    at e.createFormData (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/common/FormDataBuilder.ts:33:8)
    at e.postWithFD (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/common/Request.ts:209:43)
    at e.create (/Users/jari/Sources/okv-homepage/node_modules/mailgun.js/webpack:/mailgun/lib/Classes/Messages.ts:56:25)

This is annoying as it makes the logs quite unreadable. Of course, I could disable warnings with NODE_OPTIONS=--no-deprecation, but I would rather have the warnings as I prefer to see these from my own code.

sibelius commented 3 months ago

migrate to native node FormData https://nodejs.org/api/globals.html#class-formdata ?

olexandr-mazepa commented 1 month ago

Hi @jarimustonen As @sibelius suggested, could you try using Node.js built-in FormData implementation instead of the form-data package?

jarimustonen commented 1 month ago

I don't know how to do that. Can you tell me how I can change this? form-data is not defined as a dependency in my package.json.

olexandr-mazepa commented 1 month ago

@jarimustonen

Can you tell me how I can change this?

Sure

As you may know, native FormData support was experimentally introduced in version 16. https://nodejs.org/fr/blog/release/v16.15.0 So, please make sure you are using Node.js v16 or later.

If you are using Node.js v16, you will need to ensure you run the node process with --experimental-fetch argument, because at that time it was an experimental feature. If the argument is provided you can use FormData from the global scope without even importing it: const mailgun = new Mailgun(FormData); For Node.js v18 and later you don't need --experimental-fetch anymore and FormData is available without importing as well.

form-data is not defined as a dependency in my package.json.

I see that in the error stack error goes from node_modules/form-data/lib/form_data.js. It is hard to guess, what exactly happened, but you have this dependency even if it is absent in package.json. There are a few possible reasons:

lyalvarrez commented 1 month ago

(node:17403) [DEP0044] DeprecationWarning: The util.isArray API is deprecated. Please use Array.isArray() instead.

No sé cómo solucionar esto, me ayudan por favor.

olexandr-mazepa commented 1 month ago

(node:17403) [DEP0044] DeprecationWarning: The util.isArray API is deprecated. Please use Array.isArray() instead.

No sé cómo solucionar esto, me ayudan por favor.

Unfortunately, I do not speak Spanish. Based on auto translation I assume you still have issue.

What is the error stack in your case? Did you try to replace form-data package by native Node.js FormData?

oleksiifinkratt commented 1 month ago

This warning might also come from the wrapper package for NestJs – nestjs-mailgun. It imports FormData from form-data. I implemented my wrapper for mailgun and it works fine.