首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数@ lint脚本失败

函数@ lint脚本失败
EN

Stack Overflow用户
提问于 2018-11-09 12:31:31
回答 1查看 2.5K关注 0票数 1

我正在尝试部署Firebase,但是我得到了这个错误

错误,那么()应该返回一个值或抛出允诺/总是返回

这是我的密码

代码语言:javascript
复制
'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错误!代码ELIFECYCLE npm错误!错误1国家预防机制错误!功能@ lint:eslint . npm错误!退出状态1 npm错误!npm错误!函数@ lint脚本失败。npm错误!这可能不是npm的问题。可能还有额外的日志输出超过npm!这个运行的完整日志可以在: npm中找到!C:\Users\PC\AppData\Roaming\npm-cache_logs\2018-11-09T12_26_46_311Z-debug.log错误:函数预部署错误:命令以非零退出code1终止

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-09 12:42:21

链式then而不是嵌套,包含catch块,始终从then返回。

代码语言:javascript
复制
'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}`);

            return admin.database().ref(`/notifications/${user_id}/${notification_id}`).once('value')
                .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');
                    return null;
                })
                .catch(console.log);
        });
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53225775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档