form-data icon indicating copy to clipboard operation
form-data copied to clipboard

Type 'FormData' is not assignable to type 'BodyInit'.

Open IRediTOTO opened this issue 4 years ago • 7 comments

image

Type 'FormData' is not assignable to type 'BodyInit'.
  Type 'FormData' is missing the following properties from type 'URLSearchParams': delete, get, getAll, has, and 7 more.

Hi, I get this error when use form-data with native fetch of NextJS, How can I fix this?

IRediTOTO avatar Aug 05 '21 17:08 IRediTOTO

Hit the same issue when calling the native fetch as part of VSCode extension development. Any help?

tigerinus avatar Jan 17 '22 13:01 tigerinus

I have the same error, no updates yet ?

bfourgeaud avatar Nov 09 '22 00:11 bfourgeaud

2 years later no response?

da1z avatar Jan 29 '23 16:01 da1z

please help me, i have the same problem.

pedanmax avatar Jun 08 '23 10:06 pedanmax

Using getBuffer method of FormData should help:

body: formData.getBuffer()

Mi-ch-ael avatar Jun 08 '23 13:06 Mi-ch-ael

@IRediTOTO

Since I use NextJS too, I found its server-side runtime providing FormData (and fetch) polyfill.

So we could directely use new FormData() on the server-side code seamlessly.

  • Refer: https://github.com/vercel/next.js/blob/27953213f8f0a8bce3ee17922256b3db40a2c639/packages/next/src/compiled/%40edge-runtime/primitives/fetch.js.LEGAL.txt#L4

For others:

  • Node v18 add FormData API native support
  • NextJS using formdata-polyfill https://github.com/jimmywarting/FormData too?
  • Maybe using formdata-node https://github.com/octet-stream/form-data

kitayoshi avatar Jun 30 '23 05:06 kitayoshi