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.RNDocumentPickerThe 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
- npm i react-native-document-picker --save --force
- npx react-native start
- npx react-native run-android
Describe what you expected to happen:
- Function DocumentPicker.pick works fine, shoud pop-up a file picker for android, ios
- Be able to pick file and upload it to server
What I have already done
- Try npx react-native link, npx react-native-asset for linking
- Try npm install serveral time
- Grant access for android (in "android/app/src/main/AndroidManifest.xml")
- Change "android/settings.gradle" and "android/app/build.gradle" (according to older version of this library)
- Try older version of this library (3.x.x, 2.x.x), still have this problem
- Rebuild android by deleting app in android simulator and running "npx react-native run-android" again and again
- 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 Foundlibrary version: 8.2.0
iOS / Android version: unknown
I ran on Android simulator (of Android Studio)






