FirebaseError:Firebase:未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)。 颤动

Posted

技术标签:

【中文标题】FirebaseError:Firebase:未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)。 颤动网络【英文标题】:FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). Flutter webFirebaseError:Firebase:未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)。 颤动网络 【发布时间】:2021-12-15 12:43:22 【问题描述】:

the problem**

FirebaseError:Firebase:没有创建 Firebase 应用“[DEFAULT]”

调用 Firebase App.initializeApp() (app/no-app)。

**

7 多天以来,我一直在尝试解决我的“flutter admin web app”问题。但我做不到。

√ 我的 Firebase 身份验证是:匿名 √ Flutter(频道测试版,2.7.0-3.1.pre √ Dart 2.15 版本 √ android 工具链 - 为 Android 设备开发(Android SDK 版本 31.0.0) √ Chrome - 为网络开发 √ Android Studio(2020.3版)

我该如何解决这个问题?

请帮帮我。谁知道呢,亲爱的导师。

index.html(文件)

  <!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- ios meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="grocery_admin_app_flutter">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <title>grocery_admin_app_flutter</title>
  <link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
     application. For more information, see:
     https://developers.google.com/web/fundamentals/primers/service-workers -->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>

<script type="text/javascript">
    let useHtml = // ...
    if(useHtml) 
      window.flutterWebRenderer = "html";
     else 
      window.flutterWebRenderer = "canvaskit";
    
  </script>

<script src="main.dart.js" type="application/javascript"></script>


<script>
  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  const firebaseConfig = 
    apiKey: "AIzaSyAgoXpOjiZntQBEMqt7ZDrcFpLRmH1ZwCM",
    authDomain: "jaituncshop.firebaseapp.com",
    databaseURL: "https://jaituncshop-default-rtdb.firebaseio.com",
    projectId: "jaituncshop",
    storageBucket: "jaituncshop.appspot.com",
    messagingSenderId: "338592147861",
    appId: "1:338592147861:web:14315ce1d827ad50c1ee9c",
    measurementId: "G-TG69GZ1VSX"
  ;

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



<script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    function loadMainDartJs() 
      if (scriptLoaded) 
        return;
      
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    

    if ('serviceWorker' in navigator) 
      // Service workers are supported. Use them.
      window.addEventListener('load', function () 
        // Wait for registration to finish before dropping the <script> tag.
        // Otherwise, the browser will load the script multiple times,
        // potentially different versions.
        var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
        navigator.serviceWorker.register(serviceWorkerUrl)
          .then((reg) => 
            function waitForActivation(serviceWorker) 
              serviceWorker.addEventListener('statechange', () => 
                if (serviceWorker.state == 'activated') 
                  console.log('Installed new service worker.');
                  loadMainDartJs();
                
              );
            
            if (!reg.active && (reg.installing || reg.waiting)) 
              // No active web worker and we have installed or are installing
              // one for the first time. Simply wait for it to activate.
              waitForActivation(reg.installing ?? reg.waiting);
             else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) 
              // When the app updates the serviceWorkerVersion changes, so we
              // need to ask the service worker to update.
              console.log('New service worker available.');
              reg.update();
              waitForActivation(reg.installing);
             else 
              // Existing service worker is still good.
              console.log('Loading app from service worker.');
              loadMainDartJs();
            
          );

        // If service worker doesn't succeed in a reasonable amount of time,
        // fallback to plaint <script> tag.
        setTimeout(() => 
          if (!scriptLoaded) 
            console.warn(
              'Failed to load app from service worker. Falling back to plain <script> tag.',
            );
            loadMainDartJs();
          
        , 4000);
      );
     else 
      // Service workers not supported. Just drop the <script> tag.
      loadMainDartJs();
    
  </script>
</body>
</html>

【问题讨论】:

【参考方案1】:

我昨天遇到了同样的问题,大多数解决方案都没有解决问题。我终于解决了它,并将发布我的整个 index.html 以便您可以使用它。如果可能,请逐字使用它,当它起作用时,您就可以开始编辑了。

<!DOCTYPE html>
<html>

<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    Fore more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="fiber">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png" />

  <title>Your title</title>
  <link rel="manifest" href="manifest.json">
</head>

<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) 
      window.addEventListener('flutter-first-frame', function () 
        navigator.serviceWorker.register('flutter_service_worker.js');
      );
    
  </script>

  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-functions.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>
  <script>
    const firebaseConfig = 
      apiKey: "...",
      authDomain: "...",
      databaseURL: "...,
      projectId: "...",
      storageBucket: "...",
      messagingSenderId: "...",
      appId: "...",
      measurementId: "..."
    ;

    firebase.initializeApp(firebaseConfig);
  </script>

  <script src="main.dart.js" type="application/javascript"></script>
</body>

</html>

但只要看看你的代码,我可以告诉你这一行 &lt;script src="main.dart.js" type="application/javascript"&gt;&lt;/script&gt; 必须排在最后,因为它使用了 'app'

【讨论】:

W0W。谢谢,亲爱的,它正在工作,但 firebase 身份验证不起作用,没有记录。 对我来说,身份验证有效。 auth 给你什么错误信息? 没有错误,但没有记录。 (用户名无效)。我将与您的导师分享我的代码或回购。 github repo link 用户名无效。你能确认用户名在android上登录吗?这应该是您的代码的问题,而不是 Firebase Auth。

以上是关于FirebaseError:Firebase:未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp() (app/no-app)。 颤动的主要内容,如果未能解决你的问题,请参考以下文章

[FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).]

React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created

FirebaseError:firebase.initializeApp 中未提供“projectId”

Flutter, FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - 调用 Firebase App.ini

Stripe 和 Firebase:FirebaseError:collection() 的第一个参数应为 CollectionReference、DocumentReference 或 Fireba

firebase firestore 离线持久化 FirebaseError