[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local __init.js does not include appId #2798

Closed
samtstern opened this issue Nov 9, 2020 · 5 comments · Fixed by #3267
Closed

Local __init.js does not include appId #2798

samtstern opened this issue Nov 9, 2020 · 5 comments · Fixed by #3267

Comments

@samtstern
Copy link
Contributor

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)

@samtstern
Copy link
Contributor Author

We use this API to get the config:
https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.webApps/getConfig

The problem is that when you pass - for the appId in the REST call (as we do) the response is a partial config with no appId. Recent changes to the Analytics SDK require the appId field to be set so that the SDK can download the appropriate Analytics IDs at runtime.

@samtstern
Copy link
Contributor Author

@bkendall do you know of a way we can determine the appId in the local server? I guess if the project had exactly one Web App (likely) we could guess, but if there are multiple I am not sure what signals we have.

@ghivert
Copy link
ghivert commented Nov 9, 2020

To add a little bit to my original message, nowadays, I’m commenting out the firebase analytics in dev and re-enabling it to release in production, which is a little painful, but I can live with it.

The accuracy of Analytics in dev is not a priority for me: it’s mainly to avoid multiplying configuration between dev, staging, production, etc. The perfect for me would be to get the analytics running in dev, even if it’s not getting any result in order to maintain one index.html, and then the environment do everything else. Just a warn in the console saying that analytics could not be launched because of appId missing and continuing with other initialization would already be much better.

@bkendall
Copy link
Contributor
bkendall commented Nov 9, 2020

I do not believe we have a way today to get the AppID for a site. But, we're aware of this missing piece and we're working on it. I can't say more than that at this point, but we should have a better solution for this in the future.

@samtstern
Copy link
Contributor Author

@kmcnellis @bkendall does this issues affect Hosting in production as well or just the emulators?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants