quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

'messaging' has already been declared at firebase-messaging-sw.js

Open vaijan1990 opened this issue 9 years ago • 6 comments

Hi, I get below error. Uncaught SyntaxError: Identifier 'messaging' has already been declared at firebase-messaging-sw.js:1 Kindly help.

vaijan1990 avatar Jan 26 '17 04:01 vaijan1990

Could you please provide sample code that is causing this error (both in page and in firebase-messaging-sw.js file)

On Wed, 25 Jan 2017, 20:44 vaisshnavi janani, [email protected] wrote:

Hi, I get below error. Uncaught SyntaxError: Identifier 'messaging' has already been declared at firebase-messaging-sw.js:1 Kindly help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/99, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIh8N_eytuF8SQxNk_9uBS9NRvW7Bhoks5rWCS-gaJpZM4LuSz7 .

gauntface avatar Jan 26 '17 04:01 gauntface

firebase.initializeApp({ 'messagingSenderId': 'sender id' });

// Retrieve an instance of Firebase Messaging so that it can handle background // messages. const messaging = firebase.messaging();

and var config = { apiKey: "AIzaSyAMmou9q4KO-XVjbIKqHPIbkO3RImg_Wg4", authDomain: "push-notification-sample-fe79d.firebaseapp.com", databaseURL: "https://push-notification-sample-fe79d.firebaseio.com", storageBucket: "push-notification-sample-fe79d.appspot.com", messagingSenderId: "5898210848" }; firebase.initializeApp(config);

const messaging = firebase.messaging(); messaging.requestPermission() .then(function() { console.log('have permission'); return messaging.getToken(); }) .then(function(token){ console.log(token); }) .catch(function(err){ console.log('Error Occured',err); })

Also when I check http://localhost:8080/firebase-messaging-sw.js. this I get error page .

vaijan1990 avatar Jan 26 '17 05:01 vaijan1990

It got resolved . I removed the firebase-messaging-sw.js from include. But still getting error as code : "messaging/incorrect-gcm-sender-id", message: "Messaging: Please change your web app manifest's 'gcm_sender_id' value to '103953800507' to use Firebase messaging. (messaging/incorrect-gcm-sender-id)."

vaijan1990 avatar Jan 26 '17 06:01 vaijan1990

Found the follwoing in git page, https://github.com/realtime-framework/WebPushNotifications. "If you get the following error message it means you have changed the gcm_sender_id in your manifest.json file. Please update your manifest and enter the exact value shown in the message". But I am not sure why are we suppose to change the sender ID to the values in the message instead of the one found in Firebase console.

vaijan1990 avatar Jan 26 '17 06:01 vaijan1990

It seems that the browser sender ID for manifest.json is a fixed value, common among all FCM JavaScript clients. Overlooked in the site https://firebase.google.com/docs/cloud-messaging/js/client

vaijan1990 avatar Jan 26 '17 06:01 vaijan1990

The GCM sender ID is documents here: https://firebase.google.com/docs/cloud-messaging/js/client#configure_the_browser_to_receive_messages

gauntface avatar Jan 26 '17 15:01 gauntface