我正在学习FCM,目前正在编辑index.js文件以执行Firebase函数。然而,当我部署函数"sendPushNotifications"时,我会收到错误"解析错误:标识符"functions"已经声明。"我只在文件中声明过一次,所以我不确定它是否超出了我必须编辑的文件。我为下面代码的格式错误道歉,我仍然不太习惯将代码粘贴到SO.中
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendPushNotifications = functions.https.onRequest((req,res) => {
response.send("Attempting to send push notification...")
console.log("LOGGER --- Trying to send push mesage")
var registrationToken = 'dSXeXBSHShU:APA91bFHWw_jNF1pr8Toq3OelqtyXrTZZssJW7YHMlP-tiNJ41uuO-pS--rfWduPFEEC72FchtDRHbt1RMM1e5kSWHUDVhWFvIAtx82LjIDiUNlmk14Ix_SLtrN_vB55rbr1tgcpS3CW';
var message = {
data: {
score: '850',
time: '2:45'
},
token: registrationToken
};
admin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
return response
})
.catch((error) => {
console.log('Error sending message:', error);
throw new Error("Error sending message");
});
})
得到了相同的错误。检查您的代码,您可能已经多次声明了"const函数";(