Reputation: 73
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()
?
Upvotes: 0
Views: 1035
Reputation: 73
It was due to a bug in axios version 0.25.0 https://github.com/axios/axios/issues/4406. It's now fixed.
Upvotes: 1
Reputation: 1102
all you need is to replace the import line with this
import * as FormData from "form-data";
const formData = new FormData();
console.log(formData.getHeaders());
Upvotes: 1