Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Parsing error: Identifier 'functions' has already been declared

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");
   });
 })
like image 258
Eric Avatar asked Nov 05 '18 22:11

Eric


Video Answer


1 Answers

got the same error. Check your code, you might have declared the "const function" multiple time ;)

like image 197
Mehdi Avatar answered Oct 18 '22 01:10

Mehdi