【发布时间】:2019-04-13 00:37:40
【问题描述】:
我正在尝试部署 Firebase,但出现此错误
error 每个 then() 都应该返回一个值或者抛出 promise/always-return
这是我的代码
'use strict'
const functions = 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;
console.log('We have a notification from : ', user_id);
if(!event.data.val()){
return console.log('A Notification has been deleted from the database : ', notification_id);
}
const fromUser = admin.database().ref(`/notifications/${user_id}/${notification_id}`).once('value');
return fromUser.then(fromUserResult => {
const from_user_id = fromUserResult.val().from;
console.log('You have new notification from : ', from_user_id);
const userQuery = admin.database().ref(`Users/${from_user_id}/name`).once('value');
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return Promise.all([userQuery, deviceToken]).then(result => {
const userName = result[0].val();
const token_id = result[1].val();
const payload = {
notification: {
title : "New Friend Request",
body: `${userName} has sent you request`,
icon: "default",
click_action : "in.tvac.akshaye.lapitchat_TARGET_NOTIFICATION"
},
data : {
from_user_id : from_user_id
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('This was the notification Feature');
});
});
});
});
这是错误日志
npm 错误!代码生命周期 npm 错误!错误号 1 npm 错误!函数@ lint:
eslint .npm 错误!退出状态 1 npm 错误! npm 错误! functions@lint 脚本失败。 npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出 npm 错误!可以在以下位置找到此运行的完整日志: npm 错误! C:\Users\PC\AppData\Roaming\npm-cache_logs\2018-11-09T12_26_46_311Z-debug.log 错误:函数预部署错误:命令以非零退出代码终止1
【问题讨论】:
-
在
console.log('This was the notification Feature');之后尝试return null; -
@JamesPoag Omg,你是个超级英雄;)我怎样才能结束这个问题?
-
我发布了一个我通过 ESLint 运行的清理。请注意,我正在链接
then而不是嵌套,并且我添加了catch -
@JamesPoag 非常感谢,问题解决了:D
标签: javascript function firebase android-studio