Skip to content

Local __init.js does not include appId #2798

Closed
@samtstern

Description

See #1945


I’m using the Firebase emulators for 6 months, and I got a strange bug some weeks ago.
I’m using a lot of Firebase services and I’m using them with the hosting emulator like this:

    <script src="/__/firebase/8.0.1/firebase-app.js"></script>
    <script src="/__/firebase/8.0.1/firebase-auth.js"></script>
    <script src="/__/firebase/8.0.1/firebase-firestore.js"></script>
    <script src="/__/firebase/8.0.1/firebase-storage.js"></script>
    <script src="/__/firebase/8.0.1/firebase-functions.js"></script>
    <script src="/__/firebase/8.0.1/firebase-analytics.js"></script>
    <script src="/__/firebase/8.0.1/firebase-performance.js"></script>
    <script src="/__/firebase/init.js?useEmulator=true"></script>

One day, i got an error message Missing appId in configuration from firebase-analytics.

I struggled on this, and go to see /__/firebase/init.js. Strangely, it’s not packing the appId, although Firebase Analytics is configured on the Firebase console. So, the init.js served by the emulator:

if (typeof firebase === 'undefined') throw new Error('hosting/init-error: Firebase SDK not detected. You must include it before /__/firebase/init.js');
var firebaseConfig = {
  "projectId": "projectId",
  "databaseURL": "databaseURL",
  "storageBucket": "storageBucket,
  "locationId": "europe-west",
  "apiKey": "apiKey",
  "authDomain": "authDomain",
  "messagingSenderId": "messagingSenderId"
};
if (firebaseConfig) {
  firebase.initializeApp(firebaseConfig);

  var firebaseEmulators = undefined;
  if (firebaseEmulators) {
    console.log("Automatically connecting Firebase SDKs to running emulators:");
    Object.keys(firebaseEmulators).forEach(function(key) {
      console.log('\t' + key + ': http://' +  firebaseEmulators[key].host + ':' + firebaseEmulators[key].port );
    });

    if (firebaseEmulators.database && typeof firebase.database === 'function') {
      firebase.database().useEmulator(firebaseEmulators.database.host, firebaseEmulators.database.port);
    }

    if (firebaseEmulators.firestore && typeof firebase.firestore === 'function') {
      firebase.firestore().useEmulator(firebaseEmulators.firestore.host, firebaseEmulators.firestore.port);
    }

    if (firebaseEmulators.functions && typeof firebase.functions === 'function') {
      firebase.functions().useEmulator(firebaseEmulators.functions.host, firebaseEmulators.functions.port);
    }

    if (firebaseEmulators.auth && typeof firebase.auth === 'function') {
      firebase.auth().useEmulator('http://' + firebaseEmulators.auth.host + ':' + firebaseEmulators.auth.port);
    }
  } else {
    console.log("To automatically connect the Firebase SDKs to running emulators, replace '/__/firebase/init.js' with '/__/firebase/init.js?useEmulator=true' in your index.html");
  }
}

I couldn’t get the appId. The quick and dirty solution is to use firebase-analytics only in production, but it’s weird that one day, the emulator just stopped working. Is there anything I can do?

Originally posted by @ghivert in #1945 (comment)

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

      翻译: