You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
firestore emulator on hosting emulator does not work #3121
@lisp719 can you explain a little more what you mean by "I can access the firestore emulator from the hosting emulator." ... is there a specific line of code that is not working for you? If so could you show the code and the logs?
This is mostly html created with firebase init hosting
<!DOCTYPE html><html><head><metacharset="utf-8" /><metaname="viewport" content="width=device-width, initial-scale=1" /><title>Welcome to Firebase Hosting</title><!-- update the version number as needed --><scriptdefersrc="/__/firebase/8.2.6/firebase-app.js"></script><!-- include only the Firebase features as you need --><scriptdefersrc="/__/firebase/8.2.6/firebase-firestore.js"></script><scriptdefersrc="/__/firebase/init.js?useEmulator=true"></script></head><body><script>document.addEventListener("DOMContentLoaded",function(){firebase.firestore().doc("/foo/bar").get().then((doc)=>{console.log(doc.exists);});});</script></body></html>
# /__/firebase/init.js?useEmulator=true
Probably init.js generated by hosting emulator
if(typeoffirebase==='undefined')thrownewError('hosting/init-error: Firebase SDK not detected. You must include it before /__/firebase/init.js');varfirebaseConfig={"projectId": "tejun-6b17b","storageBucket": "tejun-6b17b.appspot.com","locationId": "us-central","apiKey": "AIzaSyD5hr25OUI9m7xUUeSVSbZsld3D-R1n9B0","authDomain": "tejun-6b17b.firebaseapp.com","messagingSenderId": "498331656419"};if(firebaseConfig){firebase.initializeApp(firebaseConfig);varfirebaseEmulators={"firestore": {"host": "0.0.0.0","port": 8080}};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&&typeoffirebase.database==='function'){firebase.database().useEmulator(firebaseEmulators.database.host,firebaseEmulators.database.port);}if(firebaseEmulators.firestore&&typeoffirebase.firestore==='function'){firebase.firestore().useEmulator(firebaseEmulators.firestore.host,firebaseEmulators.firestore.port);}if(firebaseEmulators.functions&&typeoffirebase.functions==='function'){firebase.functions().useEmulator(firebaseEmulators.functions.host,firebaseEmulators.functions.port);}if(firebaseEmulators.auth&&typeoffirebase.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");}}
As you've observed, we need a fix similar to firebase/firebase-tools-ui#312. You're welcome to open a PR to port that change to init.js in hosting emulator, or you can remove ?useEmulator=true and initialize the SDKs yourself as a local workaround.
I've had a similar issue using Docker on macOS Big Sur. It's was interesting to see that hosting using firebase serve worked as expected. That didn't meet my requirements because I also wanted the Firestore emulator to be running with it. My workaround was to setup NGINX on my container to proxy requests to localhost:5000 (which is where hosting was being exposed when launched with firebase emulators:start).
From what I could see my requests were being dropped by the hosting emulator because they were made from an external IP address. It looks like we are missing an option for "host": "0.0.0.0" on the firebase.json file.
Activity
samtstern commentedon Feb 10, 2021
@lisp719 can you explain a little more what you mean by "I can access the firestore emulator from the hosting emulator." ... is there a specific line of code that is not working for you? If so could you show the code and the logs?
lisp719 commentedon Feb 10, 2021
public/index.html
This is mostly html created with
firebase init hostingProbably init.js generated by hosting emulator
browser console error
POST to http://0.0.0.0:8080 will be net :: ERR_ADDRESS_INVALID
yuchenshi commentedon Feb 11, 2021
As you've observed, we need a fix similar to firebase/firebase-tools-ui#312. You're welcome to open a PR to port that change to
init.jsin hosting emulator, or you can remove?useEmulator=trueand initialize the SDKs yourself as a local workaround.rcopstein commentedon Feb 16, 2021
I've had a similar issue using Docker on macOS Big Sur. It's was interesting to see that hosting using
firebase serveworked as expected. That didn't meet my requirements because I also wanted the Firestore emulator to be running with it. My workaround was to setup NGINX on my container to proxy requests to localhost:5000 (which is where hosting was being exposed when launched withfirebase emulators:start).From what I could see my requests were being dropped by the hosting emulator because they were made from an external IP address. It looks like we are missing an option for
"host": "0.0.0.0"on thefirebase.jsonfile.fix(emulator): Hosting emulator should not connect to 0.0.0.0 for emu…
yuchenshi commentedon Feb 16, 2021
This is now fixed by #3141 (thank you!) and will be included in the next release.
fix(emulator): Hosting emulator should not connect to 0.0.0.0 for emu…