for the past 2 days I struggled with this problem and can't figure it out. I don't understand this error. this is my code:
try{
var formData = new FormData();
} catch (error) {
console.error('FormData ERROR', error);
}
and this is the error:
017-06-21 13:49:02.761 [error][tid:com.facebook.React.JavaScript] 'FormData ERROR', { [TypeError: undefined is not a constructor (evaluating 'new FormData()')] line: 98419, column: 36, sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false' }
Do i have to add support for FormData in ReactNative 0.45.0? please help
I got into this problem as well and that's because I have imported them on top. If you have done like what I did:
import { FormData } from 'react';
or
import { FormData } from 'react-native';
Just remove "FormData" from your imports and it will work like magic. FormData doesn't have to be imported for it to be working.
The error says that you are FormData is undefined. Since it is not part of react native, you probably have to download it from npm.
npm install --save form-data
Then import it at the top of your file
import FormData from 'form-data';
if
import { FormData } from 'react-native';
didn't help then you can try to import directly:
import FormData from 'react-native/Libraries/Network/FormData';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With