Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of null (reading 'getConstants') #716

Open
albert17 opened this issue Feb 21, 2023 · 19 comments
Open

TypeError: Cannot read properties of null (reading 'getConstants') #716

albert17 opened this issue Feb 21, 2023 · 19 comments

Comments

@albert17
Copy link

What react-native version are you using?
0.69.3

What react-native-pdf version are you using?
6.6.2

What platform does your issue occur on? (android/ios/both)
Both

Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue
    Run a test that imports PDF. Application runs fine, only npm run test fails.
  2. Interesting logs
 FAIL  __tests__/App-test.tsx
  ● Test suite failed to run

    TypeError: Cannot read properties of null (reading 'getConstants')

      4 | import { styles } from '../styles/common';
      5 | import { RootStackParamList } from '../types';
    > 6 | import Pdf from 'react-native-pdf';
        | ^
      7 |
      8 | export default function PdfSite ({ route }: NativeStackScreenProps<RootStackParamList, 'PdfSite'>) {
      9 |   return (

      at Object.getConstants (node_modules/react-native-blob-util/fs.js:14:39)
      at Object.<anonymous> (node_modules/react-native-blob-util/index.js:9:1)
      at Object.<anonymous> (node_modules/react-native-pdf/index.js:21:1)
      at Object.<anonymous> (src/screens/PdfSite.tsx:6:1)
      at Object.<anonymous> (src/App.tsx:11:1)
      at Object.<anonymous> (__tests__/App-test.tsx:6:1)

Show us the code you are using?

it('renders correctly', () => {
    act(() => {
        comp = create(<App />);
    });
@ngvcanh
Copy link

ngvcanh commented Feb 22, 2023

Same issue.

I'm using react-native:0.66.5

image

@BraveEvidence
Copy link

@kalinchuk
Copy link

@albert17 Did you find a solution for this issue?

@rajeevverma076
Copy link

Any solution

import Pdf from 'react-native-pdf';
TypeError: Cannot read properties of null (reading 'getConstants')

@testing-library/react-native

@kullarkert
Copy link

kullarkert commented Mar 29, 2023

Using with expo 48(react-native 0.71.4) same problem.

With

I get
ERROR: TypeError: Cannot read property 'DocumentDir' of null, js engine: hermes

With

ERROR: TypeError: Cannot read property 'DocumentDir' of null, js engine: hermes

With

ERROR TypeError: Cannot read property 'getConstants' of null, js engine: hermes

Maybe problem is in react-native-blob-util and not in react-native-pdf?

Searched and found this ticket: RonRadtke/react-native-blob-util#204

Original idea why it should work with expo: https://github.com/expo/examples/tree/master/with-pdf

@albert17
Copy link
Author

albert17 commented Apr 6, 2023

@kalinchuk Still facing same issue. I have tried mocking but no luck.

@PhilippLeh21
Copy link

Any update on that? Facing the same issue.

@alessandrom
Copy link

Facing the same issue

@mgithubmessier
Copy link

Same

@kullarkert
Copy link

Some solution mentioned here, but have't tested.

RonRadtke/react-native-blob-util#204 (comment)

@mgithubmessier
Copy link

@kullarkert

Some solution mentioned here, but have't tested.

RonRadtke/react-native-blob-util#204 (comment)

That's specifically for unit tests, while I'm observing this when running the app on an android simulator for realtime development.

@nikhil-tayal
Copy link

@mgithubmessier Did you add this line in android/app/build.gradle?

packagingOptions {
       pickFirst 'lib/x86/libc++_shared.so'
       pickFirst 'lib/x86_64/libjsc.so'
       pickFirst 'lib/arm64-v8a/libjsc.so'
       pickFirst 'lib/arm64-v8a/libc++_shared.so'
       pickFirst 'lib/x86_64/libc++_shared.so'
       pickFirst 'lib/armeabi-v7a/libc++_shared.so'
   }

@rohantneuro
Copy link

@mgithubmessier Did you add this line in android/app/build.gradle?

packagingOptions {
       pickFirst 'lib/x86/libc++_shared.so'
       pickFirst 'lib/x86_64/libjsc.so'
       pickFirst 'lib/arm64-v8a/libjsc.so'
       pickFirst 'lib/arm64-v8a/libc++_shared.so'
       pickFirst 'lib/x86_64/libc++_shared.so'
       pickFirst 'lib/armeabi-v7a/libc++_shared.so'
   }

try but not working

@axjrl
Copy link

axjrl commented Oct 30, 2023

Facing the same

@stuhorsfield
Copy link

For anyone running into this outside of tests in expo development builds, I ran into this today because I hadn't added the expo config plugins. Once I installed them and rebuilt the development build it all worked fine.

@dev-jwel
Copy link

react-native-blob-util depends on react native turbo module, which should be implemented with native code(android/ios).
This error may occur even we use only react-native-blob-util like this issue.
To resolve this, we may need to overwrite turbo module with jest mock.
Simplest way to suppress the error is mocking react-native-pdf itself.
This example for jest setup code may work.

jest.mock('react-native-pdf', () => { return () => <></>})

@thehemaljoshi
Copy link

react-native-blob-util depends on react native turbo module, which should be implemented with native code(android/ios). This error may occur even we use only react-native-blob-util like this issue. To resolve this, we may need to overwrite turbo module with jest mock. Simplest way to suppress the error is mocking react-native-pdf itself. This example for jest setup code may work.

jest.mock('react-native-pdf', () => { return () => <></>})

Thanks it works

@capaogg
Copy link

capaogg commented Oct 30, 2024

I think the two libraries need to be introduced at the same time to avoid this problem.i use this steps and now it works well.
1.npm uninstall react-native-pdf react-native-blob-util.
2.npm install react-native-pdf react-native-blob-util --save
3.cd android
4. ./gradlew clean
5. cd ../
6. npx react-native run-android
and now i works well,please have a try.
image

@capaogg
Copy link

capaogg commented Oct 30, 2024

I think the two libraries need to be introduced at the same time to avoid this problem.i use this steps and now it works well. 1.npm uninstall react-native-pdf react-native-blob-util. 2.npm install react-native-pdf react-native-blob-util --save 3.cd android 4. ./gradlew clean 5. cd ../ 6. npx react-native run-android and now i works well,please have a try. image

i use react-native 0.76.0
react-native-pdf 6.7.5
react-native-blob-util 0.19.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests