error Ошибка синтаксического анализа: недопустимый флаг регулярного выражения при развертывании функции в firebase - PullRequest
0 голосов
/ 23 мая 2018

создать push-уведомление с помощью node.js для моего проекта приложения для чата на android с firebase.При развертывании своей базы firebase в функции уведомлений я получаю сообщение об ошибке.

Это мой index.js в 38: 11 и 39:16 **** Это мой index.js ****

'use strict'

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

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

const user_id = event.params.user_id;
const notification = event.params.notification;

console.log("The User Id is : ",user_id);

if(!event.data.val()){

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

const fromUser = admin.database().ref(/notification/${user_id}/{notification_id}).once(value);
return fromUser.then(fromUserResult => {

    const from_user_id = fromUserResult.val().from;
    console.log('You have new notification from : ', from_user_id);

    const userQuery = admin.database().ref(`/Users/${user_id}/${notification_id}`).once('value');
    return userQuery.then(userResult => {

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

        return deviceToken.then (result => {

          const token_id = result.val();

          const payload = {
            notification : {

              title : "Friend Request",
              body : `${userName} has sent you request`,
              icon : "default"
            }
          };

          return admin.messaging().sendToDevice(token_id , payload);
        });
  });
});
});
**The cmd give me following result**


C:\Users\Ouneeb Ur Rehman\Desktop\notification function\functions\index.js
  19:40  error  Parsing error: Invalid regular expression flag

✖ 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\Ouneeb Ur Rehman\AppData\Roaming\npm-cache\_logs\2018-05-23T11_05_23_181Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit 
I try install and uninstall npn and firebase tools but alls goes to vane 

я получил идентификатор токена Firebase и сохранил в базе данных. Я новичок в узле js и не могу u введите описание изображения здесь Плз, любой может помочь Спасибо заранее

этомоя база данных уведомлений sinpit

1 Ответ

0 голосов
/ 23 мая 2018

Вы забыли кавычки в строке 19 (и должны использовать простую кавычку: ').База данных Firebase хочет получить строку, а не регулярное выражение.(cf: Справочная документация )

Строка 19 должна быть:

const fromUser = admin.database().ref('/notification/${user_id}/{notification_id}').once(value);

Обратите внимание, что регулярное выражение Javascript может принимать следующую форму:

/pattern/replacement/flags

Вот почему elint предупреждает вас о недопустимом флаге регулярного выражения.

...