Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing App configuration value: "projectId" even though I am passing it in

I am able to send, view and click on web notifications fine, and nothing appears wrong. However the console yields this when I click on a notification

Uncaught FirebaseError: Messaging: Missing App configuration value: "projectId" (messaging/missing-app-config-values).

projectId is definitely being passed to the configuration

Chrome version: Version 79.0.3945.130 (Official Build) (64-bit)

here is how I am configuring firebase:

var messaging;
if( firebase.messaging.isSupported() ){

    var config = {
      apiKey: "*************",
      authDomain: "*************",
      databaseURL: "*************",
      projectId: "*************",
      storageBucket: "*************",
      messagingSenderId: "*************",
      appId: "*************"
    };
    firebase.initializeApp(config);
    messaging = firebase.messaging();
    messaging.usePublicVapidKey("*************");
    messaging.onMessage(function(payload) {
        ...
        ...
    }
}

And my firebase-messeging-sw.js:

self.addEventListener('notificationclick', function(event) {
    ...
    ...
}
importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-messaging.js');

firebase.initializeApp({'messagingSenderId': '***********'});

const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
    ...
});

Any ideas?

like image 637
Jeff I Avatar asked Feb 14 '20 21:02

Jeff I


2 Answers

You have to call initializeApp() before calling any other Firebase APIs. Your code is calling firebase.messaging.isSupported() first before initializeApp(). It looks like perhaps you only want to initialize Firebase if FCM is going to work, but that's simply not supported. I suggest initializing Firebase unconditionally. There is very little cost to doing so if you don't actually make use of any of the Firebase products.

like image 96
Doug Stevenson Avatar answered Nov 07 '22 12:11

Doug Stevenson


I fixed this by re-getting my app's config snippet from here https://support.google.com/firebase/answer/7015592 and paste it again as my initializeApp object parameter. It was apparently caused by a Firebase upgrade.

like image 21
Louis Gualtero Avatar answered Nov 07 '22 12:11

Louis Gualtero