Firebase FCM React项目问题 - firebase-messaging-sw.js错误的类型? [英] Firebase FCM React project issue - firebase-messaging-sw.js wrong type?

查看:840
本文介绍了Firebase FCM React项目问题 - firebase-messaging-sw.js错误的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



尝试使用getToken()时:
$ ()($ {
console.log('Notification permission granted。');

  messaging.requestPermission()
.then (函数(令牌){
console.log('令牌')
})
.catch();
。 (函数(err){
console.log('无法获得通知权限',错误);
});

抛出的异常如下:

<$
$ browser $ error $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' pre>

我明白这个问题与缺少的服务工作者文件有关:firebase-messaging-sw.js,我将其添加到项目的根目录,我仍然得到相同的错误。

我不知道什么即时做错了在这里,我已经建立了香草Java脚本项目,它的工作正常....

对于这个问题的任何想法?

解决方案

为了接收消息,您将需要创建一个名为 firebase-messaging-sw.js 的文件。请参阅在Fireb中当你的web应用程序处于前台时处理消息 ase文档:
$ b


为了接收onMessage事件,您的应用程序必须在 firebase中定义Firebase消息传递服务工作者-messaging-sw.js



Im tryin to get Firebase FCM working in my React project(using webpack )

When trying to getToken() using:

 messaging.requestPermission()
  .then(function() {
    console.log('Notification permission granted.');
    return messaging.getToken();
  })
  .then(function(token) {
    console.log('token')
  })
  .catch(function(err) {
    console.log('Unable to get permission to notify.', err);
  });

the exception is thrown as follows:

browserErrorMessage: "Failed to register a ServiceWorker: The scrip 
has an unsupported MIME type ('text/html')

I understand that this issue is related to the missing service worker file: firebase-messaging-sw.js, which I added to the root of the project but I'm still getting the same error.

Im not sure what im doing wrong here, i've set up vanilla java script project and it works fine ....

Any ideas about this issue ?

解决方案

In order to receive messages, you will need to create a file called firebase-messaging-sw.js. See the section Handle messages when your web app is in the foreground in the Firebase documentation:

In order to receive the onMessage event, your app must define the Firebase messaging service worker in firebase-messaging-sw.js.

这篇关于Firebase FCM React项目问题 - firebase-messaging-sw.js错误的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆