【问题标题】:ELIFECYCLE error. How to fix it?生命周期错误。如何解决?
【发布时间】:2018-03-11 19:42:36
【问题描述】:

我在将通知功能部署到 Firebase 时遇到困难。

我也使用了 npm run clean 但错误显示在其中-

npm ERR! missing script: clean

index.js代码如下-

'use strict'

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

exports.pushNotification = 

functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {

const user_id = event.params.user_id;
const notification = event.params.notification;
console.log('We have a notification to send to : ', user_id);

if(event.data.val()){

    return console.log('A Notification has been  deleted feom the database :', notification_id);

}

const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');

return deviceToken.then(result => {

    const token_id = result.val();

    const payload = {
        notification: {
            title : "Friend Request",
            bosy : "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');

    });

});

});

命令提示符中的 firebase 部署错误是-

C:\Users\NIHIR\Desktop\MilApp\notificationFunction>firebase deploy

=== Deploying to 'milapp2-55dfb'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint 
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions
> eslint .


C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
  19:61  error  Parsing error: Unterminated template

✖ 1 problem (1 error, 0 warnings)

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\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-10T22_49_06_402Z-debug.log

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

如何解决这个错误?

在 Windows 10 中使用它。 提前致谢。

即使纠正了错误,我在部署 firebase as 时再次遇到错误-

C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
  33:53  error  Parsing error: Unexpected token ,

✖ 1 problem (1 error, 0 warnings)

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\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-11T11_27_17_307Z-debug.log

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

【问题讨论】:

    标签: node.js firebase firebase-cloud-messaging command-prompt firebase-notifications


    【解决方案1】:

    错误信息是这样的:

    19:61  error  Parsing error: Unterminated template
    

    指的是这一行的模板字符串没有终止:

    const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');
    

    您缺少该引用字符串的结束反引号。应该是这样的:

    const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken`).once('value');
    

    【讨论】:

    • 我更正了,现在我面临 Unexpected Token ,错误
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 2022-11-06
    • 1970-01-01
    • 2022-07-02
    • 2022-11-02
    • 2017-05-03
    • 2013-11-26
    • 2017-12-27
    相关资源
    最近更新 更多