简体   繁体   English

无法读取未定义的属性(读取“应用程序”)

[英]Cannot read properties of undefined (reading 'app')

Im trying to implement the firebase SDK to my Flutter web project.我正在尝试将 firebase SDK 实施到我的 Flutter Web 项目中。

But as i try to start to application the following error appear:但是当我尝试开始应用时,出现以下错误:

TypeError: Cannot read properties of undefined (reading 'app')
    at Object.app$ [as app] (http://localhost:49235/packages/firebase_core_web/src/interop/core.dart.lib.js:31:101)
    at initializeApp (http://localhost:49235/packages/firebase_core_web/firebase_core_web.dart.lib.js:108:25)
    at initializeApp.next (<anonymous>)
    at runBody (http://localhost:49235/dart_sdk.js:39250:34)
    at Object._async [as async] (http://localhost:49235/dart_sdk.js:39281:7)
    at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:49235/packages/firebase_core_web/firebase_core_web.dart.lib.js:85:20)
    at initializeApp (http://localhost:49235/packages/firebase_core/firebase_core.dart.lib.js:104:59)
    at initializeApp.next (<anonymous>)
    at runBody (http://localhost:49235/dart_sdk.js:39250:34)
    at Object._async [as async] (http://localhost:49235/dart_sdk.js:39281:7)
    at Function.initializeApp (http://localhost:49235/packages/firebase_core/firebase_core.dart.lib.js:103:20)
    at main$ (http://localhost:49235/packages/oikos_web_ec/src/widgets/modals/links/delteLink.dart.lib.js:26076:36)
    at main$.next (<anonymous>)
    at runBody (http://localhost:49235/dart_sdk.js:39250:34)
    at Object._async [as async] (http://localhost:49235/dart_sdk.js:39281:7)
    at main$ (http://localhost:49235/packages/oikos_web_ec/src/widgets/modals/links/delteLink.dart.lib.js:26074:18)
    at main (http://localhost:49235/web_entrypoint.dart.lib.js:39:29)
    at main.next (<anonymous>)
 at http://localhost:49235/dart_sdk.js:39230:33
    at _RootZone.runUnary (http://localhost:49235/dart_sdk.js:39087:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:49235/dart_sdk.js:34073:29)
    at handleValueCallback (http://localhost:49235/dart_sdk.js:34633:49)
    at Function._propagateToListeners (http://localhost:49235/dart_sdk.js:34671:17)
    at _Future.new.[_completeWithValue] (http://localhost:49235/dart_sdk.js:34513:23)
    at http://localhost:49235/dart_sdk.js:33724:46
    at _RootZone.runUnary (http://localhost:49235/dart_sdk.js:39087:58)
    at _FutureListener.then.handleValue (http://localhost:49235/dart_sdk.js:34073:29)
    at handleValueCallback (http://localhost:49235/dart_sdk.js:34633:49)
    at Function._propagateToListeners (http://localhost:49235/dart_sdk.js:34671:17)
    at _Future.new.[_completeWithValue] (http://localhost:49235/dart_sdk.js:34513:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:49235/dart_sdk.js:34536:35)
    at Object._microtaskLoop (http://localhost:49235/dart_sdk.js:39374:13)
    at _startMicrotaskLoop (http://localhost:49235/dart_sdk.js:39380:13)
    at http://localhost:49235/dart_sdk.js:34887:9

Thats the script I use in the index.html File这就是我在 index.html 文件中使用的脚本

 <script type="module">
        // Import the functions you need from the SDKs you need
        import { initializeApp } from "https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js";

        // Your web app's Firebase configuration
        const firebaseConfig = {
            apiKey: "-----....-----",
            authDomain: "-----....-----",
            projectId: "-----....-----",
            storageBucket: "-----....-----",
            messagingSenderId: "-----....-----",
            appId: "-----....-----"
        };

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

I also init everything properly at the beginning of the app with:我还在应用程序开始时使用以下命令正确初始化所有内容:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Does someone now how to fix this error?现在有人如何解决这个错误?

Use this:用这个:

https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js

in place of代替

https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js

More info更多信息

我在 Firebase 9 中遇到了类似的问题。降级到 8.x,看看它是否已解决。

I was having this issue and solved this changing the script in the index.html to this我遇到了这个问题并解决了这个问题,将 index.html 中的脚本更改为此

<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-storage.js"></script>

  <script>
    // Import the functions you need from the SDKs you need

    // 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: "...",
      authDomain: "...",
      projectId: "...",
      storageBucket: "...",
      messagingSenderId: "...",
      appId: "..."
    };

    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
  </script>

in current version only add this imports在当前版本中仅添加此导入

 import firebase from "firebase/compat/app"; import "firebase/compat/auth"; import "firebase/compat/firestore";

in the head the firebase settings file在头部 Firebase 设置文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义的属性(读取 'then') - Cannot read properties of undefined (reading 'then') 无法读取未定义的属性(读取“4”) - Cannot read properties of undefined (reading '4') 无法读取未定义的属性(读取“______”) - Cannot read properties of undefined (reading '______') 无法读取未定义的属性(读取“打开”) - Cannot read properties of undefined (reading 'on') 无法在快速应用程序中读取未定义的属性(读取“位置”) - Cannot read properties of undefined (reading 'location') in express app 反应问题无法在测验应用程序中读取未定义的属性(读取“地图”)? - React problem Cannot read properties of undefined (reading 'map') in a quiz app? TypeError:无法读取未定义的属性(读取“原型”)React APP - TypeError: Cannot read properties of undefined (reading 'prototype') React APP 无法使用部署在 Heroku 上的 React App 读取未定义的属性(读取“findOne”) - Cannot read properties of undefined (reading 'findOne') with React App deployed on Heroku 无法读取未定义的属性(读取“目标”) - Cannot read properties of undefined (reading 'target') 类型错误:无法读取未定义的属性(读取“createdTimestamp”) - TypeError: Cannot read properties of undefined (reading 'createdTimestamp')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM