Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6581

react-native-document-picker: TypeError: undefined is not an object (evaluating 'RNDocumentPicker.pick')

$
0
0

I try to use DocumentPicker.pick for file picking, but it keeps throwing error "TypeError: undefined is not an object (evaluating 'RNDocumentPicker.pick')". I traces down this error, and it leads to "node_modules/react-native-document-picker/src/index.tsx"THIS FILE

/// Line 1import { Platform, NativeModules, ModalPropsIOS } from 'react-native'/// Line 27const RNDocumentPicker: DocumentPickerType = NativeModules.RNDocumentPicker

The NativeModules seems not to exist (is blank object {} ), even when I change import line, can import NativeModules and log it out, it does not contain RNDocumentPicker.

Therefore, NativeModules.RNDocumentPicker is null, and RNDocumentPicker is NULL !?

Reproducible sample code

import DocumentPicker from "react-native-document-picker";async uploadAttachFiles() {      try {          var pickerResult = await DocumentPicker.pick({        })        console.log("🚀 ~ file: ChatInputBar.js:188 ~ ChatInputBar ~ uploadAttachFiles ~ pickerResult:", pickerResult)      } catch (e) {          console.log("🚀 ~ file: ChatInputBar.js:190 ~ ChatInputBar ~ uploadAttachFiles ~ e:", e)      }  }

I catch the error and log it there: TypeError: undefined is not an object (evaluating 'RNDocumentPicker.pick')

Steps to reproduce

  1. npm i react-native-document-picker --save --force
  2. npx react-native start
  3. npx react-native run-android

Describe what you expected to happen:

  1. Function DocumentPicker.pick works fine, shoud pop-up a file picker for android, ios
  2. Be able to pick file and upload it to server

What I have already done

  1. Try npx react-native link, npx react-native-asset for linking
  2. Try npm install serveral time
  3. Grant access for android (in "android/app/src/main/AndroidManifest.xml")
  4. Change "android/settings.gradle" and "android/app/build.gradle" (according to older version of this library)
  5. Try older version of this library (3.x.x, 2.x.x), still have this problem
  6. Rebuild android by deleting app in android simulator and running "npx react-native run-android" again and again
  7. Run './gradle clean' in android

Environment info

npx react-native info output:

info Fetching system and libraries information...System:    OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)    CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz    Memory: 7.14 GB / 15.45 GB    Shell: 5.8 - /usr/bin/zsh  Binaries:    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.15.0/bin/yarn    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm    Watchman: Not Found  SDKs:    Android SDK: Not Found  IDEs:    Android Studio: Not Found  Languages:    Java: 11.0.18 - /usr/bin/javac    Python: 2.7.18 - /usr/bin/python  npmPackages:    @react-native-community/cli: Not Found    react: 16.13.1 => 16.13.1     react-native: ^0.71.7 => 0.63.4   npmGlobalPackages:    *react-native*: Not Found

library version: 8.2.0

iOS / Android version: unknown

I ran on Android simulator (of Android Studio)


Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images