[英]error Parsing error: Invalid regular expression flag while deploying function to firebase
使用firebase為我的android聊天應用程序項目使用node.js創建推送通知。 當我在通知功能上部署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的新手,無法在此處輸入圖片描述 Plz任何人都可以提供幫助
這是我的通知數據庫sinpit
您忘記了第19行的引號(應該使用簡單的引號: '
)。 Firebase數據庫需要一個字符串,而不是正則表達式。 (請參閱: 參考文檔 )
第19行應為:
const fromUser = admin.database().ref('/notification/${user_id}/{notification_id}').once(value);
請注意,Javascript正則表達式可以采用以下形式:
/pattern/replacement/flags
這就是為什么elint警告您有關無效的正則表達式標志的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.