How to avoid loading Expo notifications bundle for web build?

ぃ、小莉子 提交于 2021-01-29 08:10:35

问题


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

  1. Install the following package:
npm install --save fbemitter
  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!