Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Fetch Blob - undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

Disclaimer

I have looked at the trouble shooting page of the wiki, however I still cannot fix the problem I am having.

RN version:

react-native-cli: 2.0.1
react-native: 0.43.4

My code:

import FileUploader from 'react-native-file-uploader'

and

<Button
    onPress={() => RNFetchBlob.fetch('POST', 'http://localhost:8000/upload', {
            'Content-Type' : 'application/octet-stream'
        }, RNFetchBlob.wrap('./tempImageStore/image.jpg'))
    }
    title={'Upload File'}
/>

Error I am getting:

simulator screen shot may 7 2017 11 04 09 am

What I did to install react-native-fetch-blob:

1) npm install --save github:wkh237/react-native-fetch-blob-package#master
2) react-native link

Background info:

  • I have tried importing it with both import RNFetchBlob from 'react-native-fetch-blob' and var RNFetchBlob = require('react-native-fetch-blob').default
  • I have tried installing it with the above code and also with npm install --save react-native-fetch-blob
  • I am trying this on the IOS emulator.

Thank you in advance for your help!

like image 383
zoecarver Avatar asked May 07 '17 19:05

zoecarver


3 Answers

After linking you need to run

pod update

inside ios folder

like image 145
Krishan Kumar Mourya Avatar answered Oct 28 '22 18:10

Krishan Kumar Mourya


So it looks like the module isn't importing. Obvious I know, I can only think of a few things to help seeing as that project looks fairly popular and stable.

I noticed that you're requiring 'react-native-file-uploader' but using 'react-native-fetch-blob'. I'm assuming this is a mistake. You could also try, if you haven't:

var RNFetchBlob = require('react-native-fetch-blob')

Now assuming you're correctly importing it, try one of the following and then restart x-code:

  1. If you haven't already restart the packager. I recall having to restart the packager every time I installed a new module.

  2. If that doesn't work, try installing deleting it from your node modules (just to be safe) and installing with cocoa pods which will handle all of the linking for you.

like image 2
klvs Avatar answered Oct 28 '22 18:10

klvs


If you are using React Native >= V.060 nothing to do

If you are using React Native <= 0.59

Check this link : https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package

like image 2
Mustapha GHLISSI Avatar answered Oct 28 '22 18:10

Mustapha GHLISSI