evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 681 forks source link

TypeError: Cannot read property 'createNotificationChannel' of undefined #1029

Open klausbreyer opened 5 years ago

klausbreyer commented 5 years ago

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

WilliamAlexander commented 5 years ago

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

christianchown commented 5 years ago

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

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

TranHuuTrung commented 4 years ago

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