本文介绍了TypeError:firebase.messaging不是node.js中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用firebase模块获取node.js中的FCM消息时,发生以下错误"TypeError:firebase.messaging不是函数".

While trying to fetch the FCM messages in node.js using firebase module, following error "TypeError: firebase.messaging is not a function" is occurring.

var firebase = require("firebase");

firebase.initializeApp({
    apiKey: "xxxxxxx",
    authDomain: "xxxxxxx",
    databaseURL: "xxxxxxx",
    projectId: "xxxxxxx",
    storageBucket: "xxxxxxx",
    messagingSenderId: "xxxxxxx"
});

const messaging = firebase.messaging();

如何纠正此错误以及如何使用Firebase模块提取消息?

How to rectify this error and how to use firebase module to pull messages??

推荐答案

您尝试使用的条件仅适用于浏览器:

The criteria you are trying to use only works on the browser:

您必须要求firebase-messaging,检查此完整示例,它将指导您 https://github.com/firebase/quickstart-js/tree/master/messaging

You have to require firebase-messaging, check this full sample it will guide you https://github.com/firebase/quickstart-js/tree/master/messaging

对于nodeJS实现,您必须使用admin.messaging

For nodeJS implementation, you have to use admin.messaging

https://firebase.google.com/docs/reference /admin/node/admin.messaging

// Get the Messaging service for the default app
var defaultMessaging = admin.messaging();

这篇关于TypeError:firebase.messaging不是node.js中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:12