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

TypeError: Cannot read property 'createNotificationChannel' of undefined

Open klausbreyer opened this issue 5 years ago • 3 comments

I am working with the example project from this repo. And I have a problem to access FCM.

    async componentDidMount() {
        console.log(FCM) //<-- i added this for debugging. 
        FCM.createNotificationChannel({
            id: 'default',
            name: 'Default',
            description: 'used for example',
            priority: 'high'
        })

And this is very weird. Because the console.log clearly shows that the FCM object is there. But then there is this error and execution of the componentDidMount ends.

image

"react": "16.4.1",
"react-native": "0.56.0",
"react-native-fcm": "^16.1.0",
"react-native-firebase": "5.0.0-rc0",

Android 8.1 Simulator

The same code is working on ios like a charm. Maybe this is linked to my other issue? https://github.com/evollu/react-native-fcm/issues/1026

klausbreyer avatar Aug 23 '18 07:08 klausbreyer

I've seen something like this before. I did following: rm -rf node_modules && npm install

WilliamAlexander avatar Aug 28 '18 12:08 WilliamAlexander

You will see this error if the native module is not compiled and linked correctly. Make sure that you have these lines

  • android\settings.gradle
    • include ':react-native-fcm' and
    • project(':react-native-fcm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fcm/android')
  • android\app\build.gradle
    • compile project(':react-native-fcm') (or implementation ....)
  • android\app\src\main\java\your\package\name\MainAppliaction.java
    • import com.evollu.react.fcm.FIRMessagingPackage;
    • new FIRMessagingPackage() in the getPackages() array

As well as the necessary google links outlined in https://github.com/evollu/react-native-fcm#android-configuration

christianchown avatar Oct 01 '18 08:10 christianchown

If you're using RN with version < 0.6 , you need use jetifier to migrate (Now I am using RN 0.59.8) and I ran following:

npm install --save-dev jetifier
npx jetify
npx react-native run-android (your app should correctly compile and work)

That worked for me as well reference: https://github.com/mikehardy/jetifier#usage-for-source-files

TranHuuTrung avatar Feb 12 '20 09:02 TranHuuTrung