react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 441 forks source link

TypeError: undefined is not an object (evaluating 'RNDocumentPicker.pick') #646

Closed SontranBK closed 1 year ago

SontranBK commented 1 year ago

Bug report

Summary

PLEASE HELP !!! 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 1
import { Platform, NativeModules, ModalPropsIOS } from 'react-native'
/// Line 27
const 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

In package.json: "react-native-document-picker": "^8.2.0",

  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)

Similar issue:

  1. https://github.com/rnmods/react-native-document-picker/issues/358
  2. https://github.com/rnmods/react-native-document-picker/issues/484
  3. https://github.com/rnmods/react-native-document-picker/issues/358
  4. https://github.com/rnmods/react-native-document-picker/issues/251
  5. https://github.com/rnmods/react-native-document-picker/issues/228
  6. https://github.com/rnmods/react-native-document-picker/issues/228
  7. https://github.com/rnmods/react-native-document-picker/issues/221
  8. https://github.com/rnmods/react-native-document-picker/issues/221
github-actions[bot] commented 1 year ago

:wave: @SontranBK, sorry you're having an issue. This issue is being closed because it does not provide all information required by the issue template. As the issue template explains, we require that you provide a runnable example that reproduces your issue and your environment information. This means you need to provide a code snippet that we can copy-paste into an empty project and see the error ourselves, or provide a git repository with the issue. The reason is that maintainers do not have time to try reproduce bugs themselves. Please try to minimize the superfluous code and focus only on reproducing the bug. Please create a new issue with this and we'll be happy to review it!