react-native-fcm
react-native-fcm copied to clipboard
TypeError: Cannot read property 'createNotificationChannel' of undefined
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.

"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
I've seen something like this before. I did following: rm -rf node_modules && npm install
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'andproject(':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 thegetPackages()array
As well as the necessary google links outlined in https://github.com/evollu/react-native-fcm#android-configuration
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