Cannot read properties of undefined (reading #39;app#39;)(无法读取未定义的属性(正在读取应用程序))
本文介绍了无法读取未定义的属性(正在读取应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将FireBase SDK实现到我的Ffltter Web项目。
但当我尝试启动应用程序时,出现以下错误:
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
这是我在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>
我还在应用程序的开头正确地初始化了所有内容:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
现在有人如何修复此错误吗?
推荐答案
我遇到了这个问题,将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>
这篇关于无法读取未定义的属性(正在读取应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:无法读取未定义的属性(正在读取应用程序)


猜你喜欢
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01