【发布时间】:2020-10-08 10:22:49
【问题描述】:
我在 Flutter Web 应用程序中使用 Firebase 服务,但在加载 firebase 脚本时遇到问题。
当我使用颤振时 run -d chrome 我看到空白页面有错误,并且在重新加载页面后加载正常:-/。
当我进行颤振构建网络时 - 页面永远不会加载,重新加载没有帮助。
基本错误: Uncaught ReferenceError: firebase is not defined
这是我在第一次启动时看到的 flutter run -d chrome:
Uncaught ReferenceError: firebase is not defined
at (index):26
app.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
require.js:143 Uncaught Error: Script error for "@firebase/app", needed by: dart_sdk
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1738)
:57663/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
当我做 flutter build web - 只有这个错误:
Uncaught ReferenceError: firebase is not defined
at Object.aoq (top_level.dart:80)
at Object.auD (cloud_firestore_web.dart:33)
at cloud_firestore_web.dart:26
at aom.a (async_patch.dart:315)
at aom.$2 (async_patch.dart:340)
at Object.G (async_patch.dart:245)
at Object.UR (main.dart:8)
at js_helper.dart:3246
at js_helper.dart:3246
at dartProgram (js_helper.dart:3246)
我的 index.html 文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>new_flowers</title>
</head>
<body>
<script src="main.dart.js" type="application/javascript"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.0/firebase-app.js"></script>
<script src ="https://www.gstatic.com/firebasejs/7.15.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.0/firebase-auth.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
</body>
</html>
【问题讨论】: