react-native-documents / document-picker

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

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNDocumentPicker' could not be found in v9.1.1 #702

Open VishnuNCS opened 4 months ago

VishnuNCS commented 4 months ago

Bug report

Summary

When I run the app in android after upgrading to v9.1.1 and selected a document and sending to m backend. All seems works fine. But when I actually execute my test suite it throws error as below

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNDocumentPicker' could not be found. Verify that a module by this name is registered in the native binary.

      2 | import { AccessibilityProps, Platform } from 'react-native';
      3 | import ReactNativeBlobUtil from 'react-native-blob-util';
> 4 | import DocumentPicker, {
        | ^
      5 |   DocumentPickerResponse,
      6 |   isInProgress,
      7 |   types,

Reproducible sample code

I have just used a snapshot for test case

const fileUpload = (
    <Provider store={store}>
      <NavigationContainer ref={navigationRef}>
        <FileUpload {...props} />
      </NavigationContainer>
    </Provider>
  );

  it('Match snapshot', () => {
    const fileUploadWithMedicalObject = render(fileUpload).toJSON();

    expect(fileUploadWithMedicalObject).toMatchSnapshot();
  });

Steps to reproduce

If you created a test case with v9.1.1 you should be able to reproduce this. Previously I was v8.1.3 didn't face any issues

Describe what you expected to happen:

  1. Even v9.1.1 should not fail with any error

Environment info

npx react-native info output:

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz
    Memory: 8.19 GB / 15.69 GB
  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\node_modules\yarn\bin\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 31, 32, 33, 34
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 32.0.0, 32.1.0, 33.0.2, 34.0.0
      System Images: android-30 | Google Play Intel x86 Atom, android-33 | Google APIs Intel x86_64 Atom
      Android NDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: AI-223.8836.35.2231.11090377
    Visual Studio: Not Found
  Languages:
    Java: 11.0.14
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^18.0.0 => 18.2.0
    react-native: 0.70.9 => 0.70.9
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

library version: 9.1.1

iOS / Android version: 17.2/13

code-jenn-or commented 4 months ago

Same error and only when running test suite, document picker works as expected in both android and iOS otherwise.

code-jenn-or commented 4 months ago

@VishnuNCS I followed this comment which resolved my tests https://github.com/rnmods/react-native-document-picker/issues/677#issuecomment-1730483250

CMDevsInc commented 4 months ago

same issue, when I just start the app

SandaruCooray commented 4 months ago

I got the same issue by linking the library and restart the metro with reset cache solve the issue

  1. first do this npx react-native-asset react-native-document-picker
  2. if you get an error saying react-natiuve.config.js not found create a new file with that name in the root folder and add this module.Exports = { project: {ios: {},android: {},},assets: ['./src/assets/fonts/'], // path of your assert file}; then try the first one again
  3. then npm start -- --reset-cache that's it :)
vonovak commented 3 months ago

Hello! The new module now comes with jest mocks, see the docs here.

thank you 🙂