Closed jarimustonen closed 3 weeks ago
migrate to native node FormData https://nodejs.org/api/globals.html#class-formdata ?
Hi @jarimustonen As @sibelius suggested, could you try using Node.js built-in FormData implementation instead of the form-data package?
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
.
@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:
npm ci
(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.
(node:17403) [DEP0044] DeprecationWarning: The
util.isArray
API is deprecated. Please useArray.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?
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.
Sending email with Mailgun spams the log files with the following warnings:
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.