【问题标题】:error Parsing error: Invalid regular expression flag while deploying function to firebase错误解析错误:将函数部署到firebase时正则表达式标志无效
【发布时间】:2018-05-23 11:39:03
【问题描述】:

使用 node.js 为我的带有 firebase 的 android 聊天应用程序项目创建推送通知。当我在通知功能上部署我的 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 令牌 ID 并存储在数据库中 我是节点 js 的新手,不能 uenter image description here 请任何人都可以提供帮助 提前致谢

这是我的通知数据库 sinpit

【问题讨论】:

  • 请编辑您的问题以准确显示错误消息。

标签: javascript firebase google-cloud-functions


【解决方案1】:

您忘记了第 19 行的引号(应该使用简单的引号:')。 Firebase 数据库需要一个字符串,而不是正则表达式。 (参见:Reference documentation

第 19 行应该是:

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

请注意,Javascript 正则表达式可以采用以下形式:

/pattern/replacement/flags

这就是 elint 警告您有关无效正则表达式标志的原因。

【讨论】:

  • yunandtidu 谢谢你的帮助,它解决了我的问题
  • 感谢你记得我 yunandtidus
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 2021-04-10
  • 1970-01-01
  • 2022-01-20
相关资源
最近更新 更多