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

5

8

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!

Ninos answered 7/5, 2017 at 19:40 Comment(2)
hey thanks for the question. but how did you make it work with cocopod please?Sillabub
The problem is with react-native link command. It is not linking the RNFetchBlob. Follow these instructions to fix it: github.com/wkh237/react-native-fetch-blob/wiki/…Plunder
A
2

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.

Analeptic answered 11/5, 2017 at 4:10 Comment(5)
I re-built the project and used cocoa pods. This worked. Thank you for the help, I will award you the 50 points in a day or two if no one else submits something that works better. Thank you again for the help.Ninos
Sure, no problem. I do think it should work without cocoapods but can't offer an explaination as to why it doesn't without dig much much deeper.Analeptic
@Ninos I understand that in order to install with cocoa pods you add the package to podfile, right? How do you do it?Trabeated
@Analeptic Why did you write 'try installing/deleting'? Not just deleting by npm/yarn and installing with cocoa pods?Trabeated
And one more thing: why is it required to install this package with cocoa pods while the others are installed with npm/yarn?Trabeated
T
5

After linking you need to run

pod update

inside ios folder

Traynor answered 4/7, 2018 at 6:39 Comment(0)
A
2

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.

Analeptic answered 11/5, 2017 at 4:10 Comment(5)
I re-built the project and used cocoa pods. This worked. Thank you for the help, I will award you the 50 points in a day or two if no one else submits something that works better. Thank you again for the help.Ninos
Sure, no problem. I do think it should work without cocoapods but can't offer an explaination as to why it doesn't without dig much much deeper.Analeptic
@Ninos I understand that in order to install with cocoa pods you add the package to podfile, right? How do you do it?Trabeated
@Analeptic Why did you write 'try installing/deleting'? Not just deleting by npm/yarn and installing with cocoa pods?Trabeated
And one more thing: why is it required to install this package with cocoa pods while the others are installed with npm/yarn?Trabeated
S
2

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

Salpingotomy answered 29/8, 2019 at 16:0 Comment(0)
H
0

Is part 2 of the installation actually

react-native link

? I think it should be

react-native link github:wkh237/react-native-fetch-blob-package#master
Hondo answered 10/5, 2017 at 12:42 Comment(1)
i am facing same error on android. Were you able to run on android? I tried almost all solution but it didn't worked. please let me know if it working for you.Corpsman
P
0

first it has changed to rn-fetch-blob https://github.com/joltup/rn-fetch-blob

then when you install it then Do the linking manually, it worked for me

https://github.com/joltup/rn-fetch-blob/wiki/Manually-Link-Package

Pastrami answered 26/3, 2019 at 16:53 Comment(1)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Protractor

© 2022 - 2024 — McMap. All rights reserved.