react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

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

Open albert17 opened this issue 2 years ago • 17 comments

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 />);
    });

albert17 avatar Feb 21 '23 11:02 albert17

Same issue.

I'm using react-native:0.66.5

image

ngvcanh avatar Feb 22 '23 03:02 ngvcanh

This could help https://www.youtube.com/watch?v=Afrd4z1aMNM https://www.youtube.com/watch?v=AHo--82qk2o

BraveEvidence avatar Mar 08 '23 07:03 BraveEvidence

@albert17 Did you find a solution for this issue?

kalinchuk avatar Mar 11 '23 19:03 kalinchuk

Any solution

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

@testing-library/react-native

rajeevverma076 avatar Mar 16 '23 07:03 rajeevverma076

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

With

[email protected]  
[email protected] 

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

With

[email protected]
[email protected] 

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

With

[email protected]  
[email protected]

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: https://github.com/RonRadtke/react-native-blob-util/issues/204

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

kullarkert avatar Mar 29 '23 07:03 kullarkert

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

albert17 avatar Apr 06 '23 16:04 albert17

Any update on that? Facing the same issue.

PhilippLeh21 avatar Apr 19 '23 12:04 PhilippLeh21

Facing the same issue

alessandrom avatar May 08 '23 13:05 alessandrom

Same

mgithubmessier avatar Jun 08 '23 15:06 mgithubmessier

Some solution mentioned here, but have't tested.

https://github.com/RonRadtke/react-native-blob-util/issues/204#issuecomment-1579012034

kullarkert avatar Jun 08 '23 17:06 kullarkert

@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.

mgithubmessier avatar Jun 08 '23 19:06 mgithubmessier

@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'
   }

nikhil-tayal avatar Sep 03 '23 10:09 nikhil-tayal

@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

rohantneuro avatar Sep 26 '23 11:09 rohantneuro

Facing the same

axjrl avatar Oct 30 '23 07:10 axjrl

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.

stuhorsfield avatar Nov 09 '23 02:11 stuhorsfield

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 () => <></>})

dev-jwel avatar Dec 25 '23 09:12 dev-jwel

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

thehemaljoshi avatar Mar 07 '24 10:03 thehemaljoshi