firebase-tools: 7.12.1
Platform: macOS and Windows (both on 7.12.1)
Reproducing is inconsistent. However, I encountered this using the Messaging quickstart with this index.html file.
I can share the demo project if you want to repro locally.
git clone https://github.com/firebase/quickstart-js.git
cd quickstart-js/messaging
firebase serve -p 8081
open https://localhost:8081/__/firebase/init.js
Note that the appId is not present.
Try visiting https://localhost:8081 and note the JS errors (quickstart won't run)
This was reproducible in several projects in different states (with only one web app, with multiple web apps, old projects and newly created ones, multiple accounts). It's consistent for any given app, but inconsistent in which apps work.
Also important to note, the apps DO HAVE an appId when viewed in the console:

The init.js file should contain appId.
The init.js file contains something similar to the following:
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": "kato-...",
"databaseURL": "https://kato-...io.com",
"storageBucket": "kato-...ot.com",
"locationId": "us-central",
"apiKey": "AIza...ePs",
"authDomain": "kato-...app.com",
"messagingSenderId": "83...95"
};
if (firebaseConfig) {
firebase.initializeApp(firebaseConfig);
}
Is it possible you had flaky internet connectivity? We recently made
changes to allow firebase serve to start offline which affect that file (it
used to refuse, now it's best effort) and I wonder if that's causing
trouble.
Doesn't mean it's any less of a bug, just trying to pin it down.
On Tue, Jan 28, 2020, 7:06 PM Kato Richardson notifications@github.com
wrote:
[REQUIRED] Environment info
firebase-tools: 7.12.1
Platform: macOS and Windows (both on 7.12.1)
[REQUIRED] Test caseReproducing is inconsistent. However, I encountered this using the Messaging
quickstart
https://github.com/firebase/quickstart-js/tree/master/messaging#getting-started
with this index.html file
https://gist.github.com/katowulf/7089ddd2cd47fdb6fac468fd0f1313d5.I can share the demo project if you want to repro locally.
[REQUIRED] Steps to reproducegit clone https://github.com/firebase/quickstart-js.git
cd quickstart-js/messaging
firebase serve -p 8081
open https://localhost:8081/__/firebase/init.js
Note that the appId is not present.
Try visiting https://localhost:8081 and note the JS errors (quickstart
won't run)This was reproducible in several projects in different states (with only
one web app, with multiple web apps, old projects and newly created ones,
multiple accounts). It's consistent for any given app, but inconsistent in
which apps work.Also important to note, the apps DO HAVE an appId when viewed in the
console:
[image: image]
https://user-images.githubusercontent.com/959972/73324681-0852bb80-4209-11ea-9224-be6ef654c6b9.png
[REQUIRED] Expected behaviorThe init.js file should contain appId.
[REQUIRED] Actual behaviorThe init.js file contains something similar to the following:
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": "kato-...",
"databaseURL": "https://kato-...io.com",
"storageBucket": "kato-...ot.com",
"locationId": "us-central",
"apiKey": "AIza...ePs",
"authDomain": "kato-...app.com",
"messagingSenderId": "83...95"
};
if (firebaseConfig) {
firebase.initializeApp(firebaseConfig);
}—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/1945?email_source=notifications&email_token=ACATB2V23SR56I5XUFK6FWDRADXCTA5CNFSM4KM53PNKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IJNFZUA,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACATB2SFWIGEDMHLILKRKADRADXCTANCNFSM4KM53PNA
.
Hey @katowulf. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
@kmcnellis showing no mercy throwing the stale bot at @katowulf !
In this particular case, it wasn't flaky connectivity, given that it's consistent for a given app/project combination, but inconsistent between multiple apps/projects. Multiple users tried about 10 projects in different states (with only one web app, with multiple web apps, old projects and newly created ones, multiple accounts) but couldn't pin down a pattern.
I have the same problem, did you all come up with a possible cause on this?
@Mauratay I think adding the appId into init.js will resolve the issue. Most likely, Sam is correct and it's because the server is not available at the point the project is initialized and the init.js is created.
Makes sense, wanted to know if it was a problem in particular with the project. Thanks
We wanted to make the Hosting emulator work offline so we made the helper that fetches the web config for __init.js into a soft fail rather than a hard fail. However what I think is happening is now it's failing for some people just due to spotty connection / intermittent backend errors and producing the strange case where you are online but your __init.js file is incomplete.
I would guess 9 times out of 10 restarting the emulator fixes it, but if you get it consistently please share debug logs!
Hi!
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?
@ghivert thank you for the clear report! That's actually a new issue, let me open a new one to discuss.