Search code examples
node.jsfirebasefirebase-cloud-messagingcommand-promptfirebase-notifications

ELIFECYCLE error. How to fix it?


I am facing difficulty in deploying the notification function to the firebase.

I also used npm run clean but the error showed in it that-

npm ERR! missing script: clean

The index.js code is as follows-

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

    });

});

});

The firebase deploy error in the Command Prompt is-

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

How to fix this error?

Using it in Windows 10. Thanks in advance.

Even after correcting the mistake, I got the error again in deploying 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

Solution

  • The error message is this:

    19:61  error  Parsing error: Unterminated template
    

    It's referring to the fact that the template string on this line isn't terminated:

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

    You're missing the closing backtick for that reference string. It should be like this:

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