gpt4 book ai didi

javascript - Firebase 部署在 Node js 上

转载 作者:行者123 更新时间:2023-11-29 23:27:57 29 4
gpt4 key购买 nike

我使用 node.js 为我使用 firebase 的 android 聊天应用程序项目创建推送通知。当我在通知功能上部署我的 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

谁能帮帮我?

最佳答案

失败是因为您的代码存在一些样式问题,而 ESLint 正在显示它。ESLint 根据其配置检查代码样式,如果有错误,它会以非零值退出,导致部署因错误而停止。

你有两种方法来解决这个问题:

  • 修复代码样式问题;
  • 更改 ESLint 配置以忽略它。

至于你的代码,它可以这样重写(虽然我没有测试它,但它应该工作相同):

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;
});

关于javascript - Firebase 部署在 Node js 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48369261/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com