Ошибка развертывания Firebase: ошибка при анализе триггеров вашей функции - PullRequest
0 голосов
/ 11 июля 2019

Я реализую функцию уведомления в своем приложении Android Studio.Я использую версию Firebase JS.Когда я запускаю команду firebase deploy, я получаю сообщение об ошибке Error occurred while parsing your function triggers.

Я пытался обновить инструменты Firebase, используя:

npm install -g firebase-tools@latest

Это мой 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.');
        });
    });
});

Я пытаюсь загрузить функции на мою консоль Firebase.Тем не менее, я получаю ошибки при вводе команды 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)

Версия моего узла v12.6.0 и версия npm 6.9.0.

1 Ответ

0 голосов
/ 11 июля 2019

Вы сохранили исходный файл?Ошибка говорит о том, что ваша строка кода выглядит так:

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

Обратите внимание, что это «продолжение» вместо «const»."cont" не является допустимым ключевым словом JavaScript.Ваш код показывает "const", поэтому, возможно, вы просто не сохранили файл перед развертыванием.

...