React-native-firebase: bug method `firebase.messaging().requestPermission` Cannot read property 'name' of undefined

Created on 21 Jun 2018  路  3Comments  路  Source: invertase/react-native-firebase

Issue

Calling firebase.message().requestPermission() gives:

TypeError: Cannot read property 'name' of undefined
    at nativeModuleKey (native.js:24)
    at getNativeModule (native.js:26)
    at requestPermission (index.js:98)
    at runCallEffect (proc.js:524)
    at runEffect (proc.js:446)
    at next (proc.js:326)
    at currCb (proc.js:399)
    at proc.js:510
    at exec (scheduler.js:25)
    at flush (scheduler.js:66)
    at asap (scheduler.js:39)

The problem is here?
https://github.com/invertase/react-native-firebase/blob/a605a703fb942c309e651fd889fc3755834a419e/lib/utils/native.js

const nativeModuleKey = (module: ModuleBase): string =>
  `${module._serviceUrl || module.app.name}:${module.namespace}`;

Is module.app null? Anyone else got this?

We called this method in another section of our app and it worked, now we moved to a better place for us and it nows gives this error. Anyone know what is happening?

Environment

tested on iOS for now

  1. Application Target Platform:

iOS

  1. Development Operating System:

Xcode 9.03, iOS 11

  1. Build Tools:

?

  1. React Native version:

RN: 0.53

  1. RNFirebase Version:
    firebase version: 4.0.3

  2. Firebase Module:

Messaging

We know we are using an old version, but we really would like to not update for now...

Most helpful comment

Looks like problem with context... but where you loose it I do not know. My problem was with redux-saga yield call(firebase.messaging().requestPermission) -> yield call([firebase.messaging(), 'requestPermission'])

All 3 comments

Looks like problem with context... but where you loose it I do not know. My problem was with redux-saga yield call(firebase.messaging().requestPermission) -> yield call([firebase.messaging(), 'requestPermission'])

FWIW: I received a similar issue but from firebase/dist because I was not smart and tried doing the following:

const batch = new firestore.batch()

return batch.update(updateFn).commit()

Rather than separating the update and commit as well as removing new from firestore.batch()

const batch = firestore.batch()
batch.update(updateFn)
return batch.commit()

I'm posting this here just in case anyone else gets here by searching for firebase or firestore & "Cannot read property 'name' of undefined"

I had the same issue with firebase and sagas. Using async where possible works too. For example, from:

const initialNotification = yield call(firebase.notifications().getInitialNotification);

to

async function getInitialNotification() {
    return await firebase.notifications().getInitialNotification();
}

// In your saga
const initialNotification = yield call(getInitialNotification);
Was this page helpful?
0 / 5 - 0 ratings