Whern i fire firebase上的简单数据库触发器, 然后它将显示如下错误: “函数返回未定义,预期的Promise或value”
const firebase=require('firebase-admin');
const functions = require('firebase-functions');
firebase.initializeApp(functions.config().firebase);
exports.helloNotification = functions.database.ref('/users').onWrite(event => {
return "A Notification has been deleted from the database ";
});
答案 0 :(得分:3)
如果您没有在函数中执行任何异步工作,只需return null
。返回字符串在云函数中没有任何意义。如果您出于某种原因需要退回承诺,请return Promise.resolve()
。
答案 1 :(得分:1)
如果您只想让错误消失,您可以只是
return new Promise((resolve, reject) => {
resolve("A Notification has been deleted from the database ")
})
但是在这里返回一个字符串是没有意义的。
如果它只是用于测试你可以
console.log("A Notification has been deleted from the database ")
代替。
答案 2 :(得分:0)
进行一些更改
代替return语句写 console.log(' ...');
在代码顶部添加'使用严格'
编写 admin 而不是 firebase 来初始化应用
代码看起来像
'use strict'
const firebase=require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
exports.helloNotification = functions.database.ref('/users').onWrite(event => {
console.log('A Notification has been deleted from the database');
});