[英]Firebase Deploy Error: Error occurred while parsing your function triggers
I am implementing a notification function on my Android Studio application. 我正在Android Studio应用程序中实现通知功能。 I am using the Firebase JS version.
我正在使用Firebase JS版本。 When I run the command
firebase deploy
, I get the error, Error occurred while parsing your function triggers
. 当我运行命令
firebase deploy
,出现错误, Error occurred while parsing your function triggers
。
I have tried to update the firebase tools using: 我尝试使用以下方法更新Firebase工具:
npm install -g firebase-tools@latest
This is my 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('/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.');
});
});
});
I am trying to upload the functions to my Firebase console. 我正在尝试将功能上传到Firebase控制台。 However, I am getting errors when I enter the command
firebase deploy
但是,当我输入命令
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)
My node version is v12.6.0
and npm version is 6.9.0
. 我的节点版本是
v12.6.0
,npm版本是6.9.0
。
Did you save your source file? 您保存了源文件吗? The error is saying that your line of code is this:
错误是说您的代码行是这样的:
cont admin = require('firebase-admin');
Notice that it's "cont" instead of "const". 请注意,它是“ cont”而不是“ const”。 "cont" is not a valid JavaScript keyword.
“ cont”不是有效的JavaScript关键字。 Your code shows "const", so maybe you just didn't save the file before deploying.
您的代码显示为“ const”,因此也许您只是在部署之前没有保存文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.