Web build broken due to Firebase initilization in main.dart
Closed this issue · 3 comments
Followed the steps on the README to get started with Firebase in a web app. Works fine from source. No issues.
Cut a build: flutter build web
and host the webapp anywhere (doesn't seem to matter nginx, apache, nodejs):
Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
I've verified my firebase-config.js is being read correctly, the firebaseConfig import has the appropriate values.
Any ideas?
Adding a "defer" to scripts loading worked for me.
<body>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script defer src="https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/8.7.0/firebase-auth.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/8.7.0/firebase-firestore.js"></script>
<script defer src="https://www.gstatic.com/firebasejs/8.7.0/firebase-analytics.js"></script>
<script defer type="module">
var firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script defer src="main.dart.js" type="application/javascript"></script>
</body>
It appears to be broken in Flutter 2.5, Dart 2.14. But in the RiverPod GitHub, it's been discussed and is a problem with Dart itself. Updating Dart to 2.15 / Flutter 2.8 (currently in Beta) fixes it. I got a notice today that Flutter 2.8 is hitting stable today. Evidently the defer isn't needed now.