wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.58k stars 534 forks source link

react-native-pdf giving error of Unable to resolve module react-native-blob-util #773

Open mohsinghafoor1 opened 9 months ago

mohsinghafoor1 commented 9 months ago

What react-native version are you using? "0.70.8" What react-native-pdf version are you using? "^6.7.1" What platform does your issue occur on? (android/ios/both) both, although i'm using expo go Describe your issue as precisely as possible : 1) Steps to reproduce the issue or to explain in which case you get the issue I'm getting a a blob pdf file from backend i want to show it on my screen. On installing react-native-pdf it gives me this error 'Unable to resolve module react-native-blob-util' on installing react-native-blob-util my app doesn't start and give me error below 2) Interesting logs TypeError: Cannot read property 'getConstants' of null, js engine: hermes ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Join a screenshot or video of the problem on the simulator or device? Show us the code you are using?

useEffect(() => { getTokens() .then((token) => { fetch(Endpoints.FUND_REPORT_FILE(props.route.params.refID), { method: 'GET', headers: { 'Authorization': Bearer ${token.access}, }, }) .then((response) => response.blob()) .then((blob) => { const reader = new FileReader(); reader.onloadend = () => { const base64Data = reader.result as string; setPdfData(data:application/pdf;base64,${base64Data}); }; reader.readAsDataURL(blob); }) .catch((error) => { console.error('Error fetching PDF:', error); }); }); }, [props.route.params.refID]);

return (
<View style={style.container}>
{pdfData ? (
  <PDFView
    source={{ uri: pdfData, cache: true }}
    onLoadComplete={() => console.log('PDF loaded')}
    onError={(error) => console.error('Error loading PDF:', error)}
    style={{ flex: 1 }}
  />
  ) : 
  (
    <ActivityIndicator size="large" color={theme.colors.primary} />
  )}
</View>

);

receppolat commented 9 months ago

What react-native version are you using? "0.70.8" What react-native-pdf version are you using? "^6.7.1" What platform does your issue occur on? (android/ios/both) both, although i'm using expo go Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue I'm getting a a blob pdf file from backend i want to show it on my screen. On installing react-native-pdf it gives me this error 'Unable to resolve module react-native-blob-util' on installing react-native-blob-util my app doesn't start and give me error below
  2. Interesting logs TypeError: Cannot read property 'getConstants' of null, js engine: hermes ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Join a screenshot or video of the problem on the simulator or device? Show us the code you are using?

useEffect(() => { getTokens() .then((token) => { fetch(Endpoints.FUND_REPORT_FILE(props.route.params.refID), { method: 'GET', headers: { 'Authorization': Bearer ${token.access}, }, }) .then((response) => response.blob()) .then((blob) => { const reader = new FileReader(); reader.onloadend = () => { const base64Data = reader.result as string; setPdfData(data:application/pdf;base64,${base64Data}); }; reader.readAsDataURL(blob); }) .catch((error) => { console.error('Error fetching PDF:', error); }); }); }, [props.route.params.refID]);

return (
<View style={style.container}>
{pdfData ? (
  <PDFView
    source={{ uri: pdfData, cache: true }}
    onLoadComplete={() => console.log('PDF loaded')}
    onError={(error) => console.error('Error loading PDF:', error)}
    style={{ flex: 1 }}
  />
  ) : 
  (
    <ActivityIndicator size="large" color={theme.colors.primary} />
  )}
</View>

);

Hi, may you send your service function (getToken), and what is FileReader? You can use Buffer from buffer, i think i can help you.