【发布时间】:2021-03-10 12:37:48
【问题描述】:
在本地服务器上成功安装我的 Flutter Web 应用程序后(使用 express 跟随 this answer),我可以在 localhost 上运行我的 Flutter 应用程序。但是,在访问它时,控制台会显示错误
main.dart.js:28998 Uncaught ReferenceError: firebase is not defined
我认为我需要在我的app.js 中安装和引用 firebase,但我实际上不知道它是如何完成的(如果确实如此的话)。我尝试运行命令 npm install firebase 似乎已成功安装它,但我仍然收到此错误。
您知道我可能遗漏了什么或为什么会收到此错误以及如何解决它吗?
请注意,如果在使用 Android Studio 构建时在 Chrome 上运行该项目可以完美运行,因此它必须与本地托管有关。
编辑
这是我当前的 index.html,当我在 Chrome 上通过 Android Studio 运行项目时,它运行良好
<!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="App test">
<!-- 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="my_app">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>My App</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://maps.googleapis.com/maps/api/js?key=MyGoogleMapsKey"></script>
<script src="main.dart.js" type="application/javascript"></script>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.5.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.1/firebase-firestore.js"></script>
<script>
<!-- Your web app's Firebase configuration-->
var firebaseConfig = {
apiKey: "apiKey",
authDomain: "my-app.firebaseapp.com",
databaseURL: "https://myApp.firebaseio.com",
projectId: "my-app",
storageBucket: "my-app.appspot.com",
messagingSenderId: "2243255670923",
appId: "1:3134567819932:web:f09e90ce142l9ikk0d2f27"
};
<!-- Initialize Firebase-->
firebase.initializeApp(firebaseConfig);
</script>
</body>
</html>
【问题讨论】:
标签: firebase express flutter dart flutter-web