pdichone / diary_webapp_course

9 stars 19 forks source link

Error: [core/not-initialized] Firebase has not been correctly initialized. #1

Open mictadlo opened 2 years ago

mictadlo commented 2 years ago

Hi, I added to index.html file the following Firebase configuration:

 <!-- The core Firebase JS SDK is always required and must be listed first -->
  <script type="module">
    // Import the functions you need from the SDKs you need
    import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js";
    import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js";
    import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js";
    import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js";

    // TODO: Add SDKs for Firebase products that you want to use
    // https://firebase.google.com/docs/web/setup#available-libraries

    // Your web app's Firebase configuration
    const firebaseConfig = {
      apiKey: "AIzaSyDoO8efzrDVveeXvqqrc39D3XiqfsyoKeU",
      authDomain: "diary-app-course-c6663.firebaseapp.com",
      projectId: "diary-app-course-c6663",
      storageBucket: "diary-app-course-c6663.appspot.com",
      messagingSenderId: "1031493909898",
      appId: "1:1031493909898:web:3cd71413645447b67c1c73"
    };

    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
  </script>

Unfortunately, I got the following error:

Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
This app is linked to the debug service: ws://127.0.0.1:33579/wuKO980VWbQ%3D/ws
Debug service listening on ws://127.0.0.1:33579/wuKO980VWbQ=/ws
💪 Running with sound null safety 💪
Connecting to VM Service at ws://127.0.0.1:33579/wuKO980VWbQ=/ws
Error: [core/not-initialized] Firebase has not been correctly initialized. Have you added the Firebase import scripts to your index.html file?
View the Web Installation documentation for more information: https://firebase.flutter.dev/docs/installation/web
    at Object.throw_ [as throw] (http://localhost:43973/dart_sdk.js:5061:11)
at http://localhost:43973/packages/firebase_core_web/firebase_core_web.dart.lib.js:90:29
at initializeApp (http://localhost:43973/packages/firebase_core_web/firebase_core_web.dart.lib.js:96:29)
    at initializeApp.next (<anonymous>)
    at runBody (http://localhost:43973/dart_sdk.js:38659:34)
    at Object._async [as async] (http://localhost:43973/dart_sdk.js:38690:7)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:43973/packages/firebase_core_web/firebase_core_web.dart.lib.js:78:20)
at initializeApp (http://localhost:43973/packages/firebase_core/firebase_core.dart.lib.js:94:59)
    at initializeApp.next (<anonymous>)

What did I miss? Michal

mictadlo commented 2 years ago

In the meantime, I did the following steps on the command line:

$ dart pub global activate flutterfire_cli
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):

  export PATH="$PATH":"$HOME/.pub-cache/bin"

$ vim ~/.bashrc
$ source ~/.bashrc

$ flutterfire configure
$ curl -sL https://firebase.tools | bash

Unfortunately, I got this error:

$ flutterfire configure
i Found 1 Firebase projects. Selecting project diary-app-course.
FirebaseProjectNotFoundException: Firebase project id "diary-app-course" could not be found on this Firebase account.
$ grep -R diary-app-course *
web/index.html:      authDomain: "diary-app-course-c6663.firebaseapp.com",
web/index.html:      projectId: "diary-app-course-c6663",
web/index.html:      storageBucket: "diary-app-course-c6663.appspot.com",

What did I miss?