React-native-fetch-blob: undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

Created on 7 May 2017  路  9Comments  路  Source: wkh237/react-native-fetch-blob

First, 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
  • Here is 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'}
/>
  • Here is the error I am getting:
    simulator screen shot may 7 2017 11 04 09 am

  • Here is 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

  • 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

Thank you in advance for your help!

Most helpful comment

I had the same problem on Android and it's because, despite having called npm link multiple times I found that it didn't actually link anything.

I fixed it by following the instructions to manually link there: https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package

Then I've deleted my "android/build" and "android/app/build" folders and ran npm start -- --reset-cache in one terminal and react-native run-android in another. After that it was working fine.

All 9 comments

Seems similar to https://github.com/wkh237/react-native-fetch-blob/issues/30, https://github.com/wkh237/react-native-fetch-blob/issues/51, https://github.com/wkh237/react-native-fetch-blob/issues/84 and https://github.com/wkh237/react-native-fetch-blob/issues/251 but so far none of the suggestions helped. This is on a fresh install with latest react-native 0.44

I did notice that my xcode project did not have any RNFetchBlob references, even though I did npm link

My issues were resolved by simply running RNFB_ANDROID_PERMISSIONS=true react-native link

same problem with RN 42.0. Open Xcode and re-build the project, then it is fixed.

react-native link solved the issue for me

I had the same problem on Android and it's because, despite having called npm link multiple times I found that it didn't actually link anything.

I fixed it by following the instructions to manually link there: https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package

Then I've deleted my "android/build" and "android/app/build" folders and ran npm start -- --reset-cache in one terminal and react-native run-android in another. After that it was working fine.

I got this error when I was running the dev server of a different app than I was launching.

Took me a couple minutes to figure it out, so maybe this will help someone who tried everything else.

image
I am having this problem even with a completely brand new project that created with

react-native init newRN

no idea why

image

image
oh, now it work, maybe because I haven't close the white window,
and also I run npm uninstall react-native-fetch-blob

now run react-native run-ios
problem gone

After linking you need to run
pod update

Was this page helpful?
0 / 5 - 0 ratings