TypeError: firebase.messaging is not a function in node.js(TypeError:firebase.messaging 不是 node.js 中的函数)
问题描述
尝试使用 firebase 模块在 node.js 中获取 FCM 消息时,出现以下错误TypeError: firebase.messaging is not a function".
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 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TypeError:firebase.messaging 不是 node.js 中的函数


基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01