Ad

Firebase Deploy Error: Error Occurred While Parsing Your Function Triggers

I am implementing a notification function on my Android Studio application. I am using the Firebase JS version. When I run the command firebase deploy, I get the error, Error occurred while parsing your function triggers.

I have tried to update the firebase tools using:

npm install -g [email protected]

This is my index.js

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

I am trying to upload the functions to my Firebase console. However, I am getting errors when I enter the command firebase deploy

Error: Error occurred while parsing your function triggers.

C:\Users\shanj\Desktop\Notification\functions\index.js:4
cont admin = require('firebase-admin');
     ^^^^^

SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at C:\Users\shanj\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:15:15
at Object.<anonymous> (C:\Users\shanj\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:53:3)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)

My node version is v12.6.0 and npm version is 6.9.0.

Ad

Answer

Did you save your source file? The error is saying that your line of code is this:

cont admin = require('firebase-admin');

Notice that it's "cont" instead of "const". "cont" is not a valid JavaScript keyword. Your code shows "const", so maybe you just didn't save the file before deploying.

Ad
source: stackoverflow.com
Ad