简体   繁体   English

Firebase部署错误:解析函数触发器时发生错误

[英]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.

相关问题 Firebase函数部署错误:解析函数触发器时发生错误 - Firebase Functions deploy error : Error occurred while parsing your function triggers 解析功能触发器时出现Firebase错误 - Cloud Functions for Firebase Error occurred while parsing your function triggers firebase部署错误:“解析函数触发器时发生错误” - firebase deployment error:“error occured while parsing your function triggers” 错误:在部署云功能时解析触发器时出错 - Firebase - Error: Error parsing triggers while deploying cloud functions - Firebase Firebase 云 Function (Javascript) Firebase 部署时解析错误 - Firebase Cloud Function (Javascript) Parsing Error When Firebase Deploy 将功能部署到Firebase时出错 - Error with deploy function to Firebase 解析EntityName XMLHttpRequest请求时发生错误 - An error occurred while parsing EntityName XMLHttpRequest Request Firebase:解析触发器时出错:无法找到模块&#39;request-promise&#39;简单云功能 - Firebase: Error parsing triggers: Cannot find module 'request-promise' simple cloud function 部署Firebase时解析错误 - Parsing error while deploying firebase 获取 `eslint' - 解析错误,同时编译 firebase 云 function - Getting `eslint' - parsing error, while compiling firebase cloud function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM