Firebase FCM参考错误的云端函数
错误
ReferenceError:函数没有在Object中定义。 在Module._compile(module.js:570:32)位于Object.Module._extensions..js(module)的模块(C: Users CROWDE〜1 AppData Local Temp fbfn_9612Si4u8URDRCrr index.js:5:21)在module.load(module.js:487:32)上,在Module.require上的Function.Module._load(module.js:438:3)处的tryModuleLoad(module.js:446:12)处调用.js:579:10) (module.js:497:17),位于C: Users crowderia AppData Roaming npm node_modules firebase-tools lib triggerParser.js中的require(internal / module.js:20:19):18:在对象11。 (C:用户 crowderia 应用程序数据漫游 NPM node_modules 火力工具 lib中 triggerParser.js:32:3)
像下面的index.js文件
'use strict'
const funnctions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id;
const notification_id = event.params.notification_id;
cosole.log('User id is : ', user_id);
if (!event.data.val()) {
return console.log('A Notification has been deleted from the database : ', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title: "Friend Request",
body: "You've received a new Friend Request",
icon: "default",
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('this is the notification feature');
});
});
});
你在第一行有一个错字
const funnctions = require('firebase-functions');
函数,而不是funn :) :)这一行
functions.database.ref('/通知/ {USER_ID ...
会工作
链接地址: http://www.djcxy.com/p/33039.html上一篇: Cloud Functions for Firebase FCM reference error
下一篇: How to access io.emit() from routes/index? on express 4.15