I'm learning FCM and I'm currently editing the index.js file to execute Firebase functions. However, when I deploy the function 'sendPushNotifications' I receive the error "Parsing error: Identifier 'functions' has already been declared." I've only declared it once within the file so I'm not sure if it's something beyond the file that I have to edit. I apologize for the poor formatting of the code below, I'm still not too used to pasting code into 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");
});
})
got the same error. Check your code, you might have declared the "const function" multiple time ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With