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

Cannot read property 'rnfbEncode' of undefined, js engine: hermes #321

Closed
mMarcos208 opened this issue Dec 5, 2023 · 20 comments
Closed

Comments

@mMarcos208
Copy link

My code

import {Platform} from 'react-native'
import ReactNativeBlobUtil, {ReactNativeBlobUtilConfig} from 'react-native-blob-util'


export const options = (name: string, extension = 'pdf', notification = true) => {
  const {fs} = ReactNativeBlobUtil
  const {
    dirs: {DocumentDir, DownloadDir},
  } = fs
  return Platform.select({
    ios: {
      fileCache: true,
      path: `${DocumentDir}/${name}`,
      title: name,
    },
    android: {
      fileCache: true,
      addAndroidDownloads: {
        useDownloadManager: true,
        notification,
        title: name,
        path: `${DownloadDir}/${name}.${extension}`,
      },
    },
  }) as ReactNativeBlobUtilConfig
}

import {useCallback, useState} from 'react'
import {Platform} from 'react-native'
import ReactNativeBlobUtil from 'react-native-blob-util'

import {options} from '@/utils/blob'
import {filesPermission} from '@/utils/hardwarePermissions'

export const useFetchBlob = () => {
  const [progress, setProgress] = useState<number>()

  const fetchBlob = useCallback(
    async (
      url: string,
      name: string,
      extension?: string,
      headers?: {
        [key: string]: string
      },
    ) => {
      try {
        const hasDownloadPermission = await filesPermission()
        if (hasDownloadPermission) {
          const {config} = ReactNativeBlobUtil

          const res = await config(options(name, extension))
            .fetch('GET', url, headers)
            .progress((received, total) => {
              setProgress(received / total)
            })

          if (Platform.OS === 'ios') {
            ReactNativeBlobUtil.ios.previewDocument(res.path())
          }
        } else {
        }
      } catch (error) {} finally {
        setProgress(undefined)
      }
    },
    [progress],
  )

  return {
    progress,
    fetchBlob,
  }
}


"react-native": "0.72.7"
"react-native-blob-util": "^0.19.6",

@Mohamed-Sheik-Ali
Copy link

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

@RemiHin
Copy link

RemiHin commented Dec 8, 2023

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

I have the same issue, reverting back to 0.19.4 solved it for now

@appa-gomi
Copy link

Comment the two line(273, 274) in fetch.js

                         fs.session(options.session).add(data);
                 }
                 respInfo.rnfbEncode = rawType;
-                if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
-                    respInfo = responseInfo;
+                // if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
+                //     respInfo = responseInfo;
                 resolve(new FetchBlobResponse(taskId, respInfo, data));
             }

@zehratok
Copy link

Comment the two line(273, 274) in fetch.js

                         fs.session(options.session).add(data);
                 }
                 respInfo.rnfbEncode = rawType;
-                if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
-                    respInfo = responseInfo;
+                // if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
+                //     respInfo = responseInfo;
                 resolve(new FetchBlobResponse(taskId, respInfo, data));
             }

This method worked for me, thank you. However, I didn't understand why such a change was made in the package; the commit messages were not explanatory.

@MohamedMegdich1
Copy link

MohamedMegdich1 commented Dec 28, 2023

Hi @mMarcos208, I have fixed this issue by wrapping the path with path: ReactNativeBlobUtil.wrap(filePath)

`
import {Platform} from 'react-native'
import ReactNativeBlobUtil, {ReactNativeBlobUtilConfig} from 'react-native-blob-util'

export const options = (name: string, extension = 'pdf', notification = true) => {
const {fs} = ReactNativeBlobUtil
const {
dirs: {DocumentDir, DownloadDir},
} = fs
return Platform.select({
ios: {
fileCache: true,
path: ReactNativeBlobUtil.wrap(${DocumentDir}/${name}),
title: name,
},
android: {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true,
notification,
title: name,
path: ReactNativeBlobUtil.wrap( ${DownloadDir}/${name}.${extension}),
},
},
}) as ReactNativeBlobUtilConfig
}
`

@imanshul
Copy link

imanshul commented Jan 30, 2024

Any update? still facing this issue, and downgrading to 0.19.4 also doesn't resolve the issue

@TheWirv
Copy link

TheWirv commented Feb 9, 2024

Comment the two line(273, 274) in fetch.js

                         fs.session(options.session).add(data);
                 }
                 respInfo.rnfbEncode = rawType;
-                if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
-                    respInfo = responseInfo;
+                // if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
+                //     respInfo = responseInfo;
                 resolve(new FetchBlobResponse(taskId, respInfo, data));
             }

This patch also fixed the issue for me, thanks!

@obinote
Copy link

obinote commented Feb 13, 2024

diff --git a/node_modules/react-native-blob-util/fetch.js b/node_modules/react-native-blob-util/fetch.js
index ed4e67f..fe541e5 100644
--- a/node_modules/react-native-blob-util/fetch.js
+++ b/node_modules/react-native-blob-util/fetch.js
@@ -270,8 +270,8 @@ export function fetch(...args: any): Promise {
                         fs.session(options.session).add(data);
                 }
                 respInfo.rnfbEncode = rawType;
-                if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
-                    respInfo = responseInfo;
+                // if ('uninit' in respInfo && respInfo.uninit) // event didn't fire yet so we override it here
+                //     respInfo = responseInfo;
                 resolve(new FetchBlobResponse(taskId, respInfo, data));
             }
 

It work for me.

@Sakib-203-15-3883
Copy link

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

It works for me.

@RonRadtke
Copy link
Owner

RonRadtke commented Feb 13, 2024

Can you tell me in which line this fails exactly?
Does it happen on Android or iOS or both?
Would like to fix this.

But to explain the changes.
There are cases where the native events are triggered after the callback is triggered. Therefor the callback gets all information and if the event happens to arrive after the callback we still can resolve with all required information.

Just that seems like I missed something

@maksimko
Copy link

In my case it only happens on Android. The same code on iOS works fine.
Version 0.19.4 works well on both platforms.

@raymondjacobson
Copy link

+1 seeing this issue. 0.19.4 fixes it for me as well.

@endrits079
Copy link

Hi @mMarcos208, I have fixed this issue by wrapping the path with path: ReactNativeBlobUtil.wrap(filePath)

` import {Platform} from 'react-native' import ReactNativeBlobUtil, {ReactNativeBlobUtilConfig} from 'react-native-blob-util'

export const options = (name: string, extension = 'pdf', notification = true) => { const {fs} = ReactNativeBlobUtil const { dirs: {DocumentDir, DownloadDir}, } = fs return Platform.select({ ios: { fileCache: true, path: ReactNativeBlobUtil.wrap(${DocumentDir}/${name}), title: name, }, android: { fileCache: true, addAndroidDownloads: { useDownloadManager: true, notification, title: name, path: ReactNativeBlobUtil.wrap( ${DownloadDir}/${name}.${extension}), }, }, }) as ReactNativeBlobUtilConfig } `

worked for me

@paskalov-aris
Copy link

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

Downgrading from 0.19.6 to 0.19.4 fixed the error in my case. Thanks.

@mMarcos208
Copy link
Author

Downgrade to 0.19.4 cause this error #204

@RonRadtke
Copy link
Owner

RonRadtke commented Feb 23, 2024

@mMarcos208 @paskalov-aris @endrits079
Anyone can tell we whitch line is causing the probelm?
And is it an on progress event or when the request is finished?
Android / ios / both?

Some more information to reproduce it would be great so you don't have to downgrade

@bhavdeep-pixer
Copy link

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

It's also worked for me. Thanks @Mohamed-Sheik-Ali

@RonRadtke
Copy link
Owner

@mMarcos208 @paskalov-aris @endrits079 Anyone can tell we whitch line is causing the probelm? And is it an on progress event or when the request is finished? Android / ios / both?

Some more information to reproduce it would be great so you don't have to downgrade

@bhavdeep-pixer same question to you.

RonRadtke pushed a commit that referenced this issue Feb 26, 2024
hopefully fixes this issue
@herberthk
Copy link

Hi @mMarcos208 I think the issue is with package version, I also stumbled on the same error. So, I downgraded the version to react-native-blob-util@0.19.4 it works for me. Hope it helps.

Thanks solved my issue

@sadewole
Copy link

sadewole commented May 6, 2024

The file got downloaded but cannot locate it in the device file manager. It was downloaded to the internal app which is not visible.

How can this be fixed, please?

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