Search code examples
javascriptreact-nativeexpoform-data

Can't access any method of formData object in React Native, except append


I'm trying to run the following code in react native(Expo):

import FormData from "form-data"; // installed with npm install 'form-data'

const formData = new FormData();

console.log(formData.getHeaders());    <------- formData.getHeaders is not a function. (In 'formData.getHeaders()', 'formData.getHeaders' is undefined)

But the only method that works is append.

getHeaders() works if I run the above code with node, but doesn't work in react native app.

Why doesn't it recognize the FormData methods such as getHeaders() or getBoundary()?


Solution

  • It was due to a bug in axios version 0.25.0 https://github.com/axios/axios/issues/4406. It's now fixed.