Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 分析错误时出错:将函数部署到firebase时,正则表达式标志无效_Javascript_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript 分析错误时出错:将函数部署到firebase时,正则表达式标志无效

Javascript 分析错误时出错:将函数部署到firebase时,正则表达式标志无效,javascript,firebase,google-cloud-functions,Javascript,Firebase,Google Cloud Functions,使用node.js为firebase的android聊天应用程序项目创建推送通知。当我在通知功能上部署firebase时,我遇到了一些错误 这是我38:11和39:16的index.js ****这是我的index.js**** 'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.c

使用node.js为firebase的android聊天应用程序项目创建推送通知。当我在通知功能上部署firebase时,我遇到了一些错误

这是我38:11和39:16的index.js ****这是我的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并存储在数据库中 我是node js的新手,无法使用u 请大家帮忙 提前谢谢


这是我的通知数据库sinpit

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

第19行应为:

const fromUser = admin.database().ref('/notification/${user_id}/{notification_id}').once(value);
请注意,Javascript正则表达式可以采用以下形式:

/pattern/replacement/flags

这就是为什么elint警告您一个无效的正则表达式标志

请编辑您的问题以准确显示错误信息。yunandtidu感谢您的帮助,它解决了我的问题,并记住了我yunandtidu