【问题标题】:Error: [core/not-initialized] Firebase has not been correctly initialized错误:[核心/未初始化] Firebase 未正确初始化
【发布时间】:2022-01-18 02:08:18
【问题描述】:

我找到了this 项目。在我添加到index.html 文件后,下面的 Firebase 配置:

 <!-- 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>

不幸的是,我收到以下错误:

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>)

我错过了什么?

【问题讨论】:

    标签: firebase flutter flutter-web


    【解决方案1】:

    Flutter 团队发布了一个 cli,您现在可以使用它来将您的项目连接到 firebase

    要遵循的步骤

    1. 确保你有firebase cli
    2. 接下来,通过运行以下命令安装 FlutterFire CLI:
    dart pub global activate flutterfire_cli
    
    1. 在应用程序的根目录中,运行配置命令:
    flutterfire configure
    
    1. 按照提示操作,将生成一个 firebase 选项文件

    2. 然后,通过 DefaultFirebaseOptions 类中的 currentPlatform getter 提供当前平台选项:

    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    

    【讨论】:

    • 我遇到了 flutterfire configure i Found 1 Firebase 项目。选择项目日记-应用-课程。 FirebaseProjectNotFoundException:在此 Firebase 帐户上找不到 Firebase 项目 ID“diary-app-course”。 但是,Firebase 仪表板显示 diary-app-course 及以下 diary-app-course-c6663。我错过了什么?
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2021-09-19
    • 2019-12-10
    • 2020-04-21
    • 2012-06-17
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多