繁体   English   中英

我尝试部署 function 时出错

[英]Error while i am trying to deploy the function

我正在尝试部署我的代码,但出现错误

我的索引代码是:

'use strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


exports.sendNotification = 
functions.database.ref('/Notifications/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
const receiver_user_id = context.params.receiver_user_id;
const notification_id = context.params.notification_id;

console.log('We have a notification to send to :' , receiver_user_id);

if (!data.after.val())
{
    console.log('A notification has been deleted :' , notification_id);
    return null;
}

const DeviceToken = admin.database().ref(`/Users/${receiver_user_id}/device_token`).once('value');

return DeviceToken.then(result =>
{
    const token_id = result.val();

    const payload =
    {
        notification:
        {
            title: "New Chat Request",
            body: `you have a new Chat Request, Please Check.`,
            icon: "default"
        }
    };

    return admin.messaging().sendToDevice(token_id, payload)
    .then(response =>
        {
            console.log('This was a notification feature.');
        });
});
});

显示的错误是这样的:

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\Admin\AppData\Roaming\npm-cache\_logs\2020-06-02T11_48_47_185Z-debug.log
events.js:287
      throw er; // Unhandled 'error' event
      ^
}

Error: functions predeploy error: Command terminated with non-zero exit code1


The error shown in C:\Users\Admin\AppData\Roaming\npm-cache_logs\2020-06-02T11_48_47_185Z-debug.log :



 error code ELIFECYCLE

 error errno 1

 error functions@ lint: `eslint .`

 error Exit status 1

 error Failed at the functions@ lint script.

 error This is probably not a problem with npm. There is likely additional logging output above.

 verbose exit [ 1, true ]

您需要在此处捕获错误:

then(response =>
        {
            console.log('This was a notification feature.');
        }).catch(error => handle error here)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM