如何解决错误:函数预部署错误:命令以非零退出代码终止

时间:2020-05-03 12:49:31

标签: javascript firebase google-cloud-functions

当我尝试在Firebase中部署此错误时,错误不断:“命令以非零退出代码1终止”。请帮助我解决这个问题。我将非常感谢您。我想制作一个用户可以在其中收到通知的应用程序,当他单击通知时,它应该打开一个新活动。

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


   admin.messaging().sendToDevice(token_id, payload).then(response => {

    console.log('This was the notification Feature');

  });

});

});

});

0 个答案:

没有答案