我使用firebase为我的android聊天应用项目创建了node.js的推送通知。 当我在通知功能部署我的firebase时,我遇到了一些错误。
这是我的index.js 在38:11和39:16
const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`).once('value');
return deviceToken.then(response =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "Friend Request",
body: "you have received a new friend request",
icon:"default"
}
};
38. return admin.messaging().sendToDevice(token_id, payload)
39. .then(response =>
{
console.log('This was the notification feature.');
});
});
这是我的错误
Running command: npm --prefix %RESOURCE_DIR% run lint
> functions@ lint C:\Users\Iax\Desktop\NotificationFunction\functions
> eslint .
C:\Users\Iax\Desktop\NotificationFunction\functions\index.js
38:11 warning Avoid nesting promises promise/no-nesting
39:16 error Each then() should return a value or throw promise/always-return
✖ 2 problems (1 error, 1 warning)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Iax\AppData\Roaming\npm-cache\_logs\2018-01-21T16_30_37_019Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
Having trouble? Try firebase deploy --help
任何人都可以帮助我吗?
答案 0 :(得分:1)
它失败了,因为您的代码存在一些样式问题并且ESLint正在显示它。 ESLint根据其配置检查代码样式,如果有错误,则以非零退出,导致部署停止并出现错误。
您有2种方法可以解决这个问题:
至于你的代码,它可以用这种方式重写(虽然我没有测试它,但它应该工作相同):
const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`).once('value');
return deviceToken.then(response => {
const token_id = result.val();
const payload = {
notification:
{
title: "Friend Request",
body: "you have received a new friend request",
icon:"default"
}
};
return admin.messaging().sendToDevice(token_id, payload);
}.then(response => {
console.log('This was the notification feature.');
return true;
});