I am using expo and react native web. I have integrated FCM for notifications for web but expo also loads a notifications bundle which I do not want.
The issue is when the notification is received in the browser and message is clicked, the app gets the focus but crashes saying “TypeError: _emitter is undefined”. This is on this line in src/Notifications/Notifications.ts:40
_emitter.emit('notification', notification);
So, it seems expo tries to use its Notifications module. Can I remove that for web build?
The following solution works for me in web environment.
1. Install the following package:
npm install --save fbemitter
2. Update your code:
import * as Notifications from 'expo/build/Notifications/Notifications'
// By calling "Notifications.default.addListener()" function,
// the _emitter variable will be initialized correctly
Notifications.default.addListener(event => {
console.log('message data', event.data)
})
// Now you should NOT need another one listener:
/*
navigator.serviceWorker.addEventListener('message', event => {
console.log('message data', event.data)
})
*/