问题
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?
回答1:
Solution 1 - Upgrade to expo@39.0.4:
npm install expo@39.0.4
Solution 2 - Initialize _emitter property
- Install the following package:
npm install --save fbemitter
- Add a listener in your App.js/tsx file
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)
})
来源:https://stackoverflow.com/questions/65368235/how-to-avoid-loading-expo-notifications-bundle-for-web-build