wkh237/react-native-fetch-blob

[Android] undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

Closed this issue Β· 24 comments

dphov commented

Hello!

This error appears at start launch in the simulator/device.

In my example I'm trying implement this part of code, how we can avoid this issue?

Thank you in advance.

componentDidMount() { RNFetchBlob .config({ // add this option that makes response data to be stored as a file, // this is much more performant. fileCache : true, }) .fetch('GET', 'https://homepages.cae.wisc.edu/~ece533/images/mountain.png') .then((res) => { // the temp file path console.log('The file saved to ', res.path('/')) }) requestPermission("android.permission.ACCESS_FINE_LOCATION").then((result) => { console.log("Granted!", result);// now you can set the listenner to watch the user geo location }, (result) => { console.log("Not Granted!"); console.log(result); });

react-native@0.29.0
react-native-cli@1.0.0
react@15.2.0
react-native-fetch-blob@0.6.3-dev.1

img1
img2

Hi @dphov , It looks like your package is not linked properly, did you restart your packager after install the package ? the module has many native code so you have to rebuild the project after install it.

dphov commented

Hi @wkh237 ,

  1. I'm has restarted packager
  2. Ran npm install
  3. Then ran rnpm link

And I got the same error

Did you save the package dependency to package.json ? rnpm does not work if the package could not be found in package.json.

could you try the following commands ?

$ npm install --save react-native-fetch-blog@0.6.3-dev.1
$ rnpm link react-native-fetch-blob
$ react-native run-android
dphov commented

package.json after running commands
"dependencies": { "react": "15.2.0", "react-native": "0.29.0", "react-native-android-permissions": "^0.0.6", "react-native-cli": "^1.0.0", "react-native-fetch-blob": "^0.6.3-dev.1", "undefined": "^0.1.0" }

got same error again

This may also related to changes in 0.29 , could you check MainApplication.java in /android/app/src/main/java/com/<project name>t/MainApplication.java, see if the RNFetchBlobPackage is added into package list ?

 @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          // Add this line if it does not exists
+         new RNFetchBlobPackage()                                                                                                                
      );
    }

Add the missing package and compile to see if it work πŸ‘

  • Add 0.29 instruction to README.md
  • Change rnpm link script
dphov commented

Hurray! It works! Thank you!

That's great πŸ‘ Please feel free file an issue if something's going wrong πŸ˜„

dphov commented

Sure! πŸ˜„ πŸ‘

Commenting just in case anyone encounter the same issue when compiling IOS.

I have also encountered this when I transfer my project to a new macbook.

Solution:
Run the app on the simulator.
Delete away the build file inside IOS folder.
At the simulator, go to Simulator > Reset content and setting
Rebuild the app again - react-native run-ios

Credits to this link: http://stackoverflow.com/questions/35611765/react-native-run-ios-command-fails-pch-issues-but-build-succeeds-in-xcode

@shirleycharlin , great thanks for your additional information πŸ‘

I am still having this same issue @dphov reported, I have done the linking but the error persists on Android. Is there any other reason

 RNFetchBlob 

will be undefined? Cos I get error undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

  1. "react-native-fetch-blob": "^0.8.2",
  2. "react-native": "0.30.0",

@RichardBoyewa , I've write some instructions in other thread, let's discuss this issue here, Thank you: )

I'm getting the error not able to find the symbol RNFetchBlobPackage after adding the package in main application

before that i was getting the error undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

Two things solved the problem for me:
1- use the react-native link command
2- deploy the app again to the device from android studio ( i think using the package manager (npm start) only packages the new javascript code, not the library native code )

@dphov
How did you resolve this issue? I have the same error on Android emulator.
My dependencies from package.json:

"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-drawer": "^2.3.0",
"react-native-fetch-blob": "^0.10.5",
"react-native-localization": "^0.1.30",
"react-native-router-flux": "3.39.1",
"react-native-video": "^1.0.0"
},

@wkh237 @shirleycharlin I got the same issue when compiling IOS, but it work when compiling Android.I follow your steps to solve, but still not work.

dependencies:
1、"react-native": "0.44.0",
2、"react-native-fetch-blob": "^0.10.8"

Compile Error:
** BUILD FAILED **

The following build commands failed:
CompileC /Users/leo/code/RNDemo/ios/build/Build/Intermediates/TcpSockets.build/Debug-iphonesimulator/TcpSockets.build/Objects-normal/x86_64/TcpSockets.o TcpSockets.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/RNDemo.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/RNDemo.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist

For future posterity: I also ran into this problem because I was accidentally still running a React packager for a different project. I assume they got their wires crossed somehow. Not sure if it's expected to be able to run 2 packagers side-by-side or not?

If you are making a Activity and implementing DefaultHardwareBackBtnHandler, then in your onCreate(Bundle savedInstanceState), use addPackage() method like this:

mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModulePath("index.android") .addPackage(new MainReactPackage()) .addPackage(new RNFetchBlobPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build();

After linking you need to run
pod update

This is solution for Android build. I didn't have any issues with iOS, some of these steps might help for iOS as well.

First make sure the package is installed

npm install react-native-fetch-blog

Next make sure it's included your package.json file (your version number might be different, just make sure it's there)

"dependencies": {
  "react-native-fetch-blob": "^0.10.8",
}

Next link the react-native-fetch-blob package directly using

react-native link react-native-fetch-blob

Next verify that the package is included in app/src/main/java/com/[APP-NAME]/MainApplication.java. Find the getPackages() function, inside there you should see new MainReactPackage(), among other packages. Look for new RNFetchBlogPackage(), if it's not in this list, add it.

new RNFetchBlogPackage()

Try to build the project. If you get an error error: cannot find symbol new RNFetchBlobPackage() then go back to the file app/src/main/java/com/[APP-NAME]/MainApplication.java and add

import com.RNFetchBlob.RNFetchBlobPackage;

to the top with the other imports. Try to build and it should work.

All these steps ended up working for me and the project was built.