在没有android studio的情况下本地运行Flatter web应用程序会引发firebase错误

在没有android studio的情况下本地运行Flatter web应用程序会引发firebase错误,firebase,express,flutter,dart,flutter-web,Firebase,Express,Flutter,Dart,Flutter Web,在本地服务器上成功安装了我的颤振web应用程序后(接下来使用express),我就可以在本地主机上运行我的颤振应用程序了。但是,在访问它时,控制台会显示错误 main.dart.js:28998未捕获引用错误:未定义firebase 我假设我需要在我的app.js中安装和引用firebase,但实际上我不知道它是如何完成的(如果真是这样的话)。我试着运行命令npm install firebase,该命令似乎成功地安装了它,但是我仍然收到这个错误 你知道我可能遗漏了什么,或者为什么会出现这个错误

在本地服务器上成功安装了我的颤振web应用程序后(接下来使用express),我就可以在本地主机上运行我的颤振应用程序了。但是,在访问它时,控制台会显示错误

main.dart.js:28998未捕获引用错误:未定义firebase

我假设我需要在我的
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>

我的应用程序
if(导航器中的“serviceWorker”){
window.addEventListener('flatter-first-frame',函数(){
navigator.serviceWorker.register('flatter_service_worker.js');
});
}
var firebaseConfig={
apiKey:“apiKey”,
authDomain:“我的app.firebaseapp.com”,
数据库URL:“https://myApp.firebaseio.com",
projectId:“我的应用程序”,
storageBucket:“我的app.appspot.com”,
messagingSenderId:“2243255670923”,
appId:“1:3134567819932:web:f09e90ce142l9ikk0d2f27”
};
firebase.initializeApp(firebaseConfig);

确保在web文件夹的
index.html
中包含整个firebase脚本和正在使用的服务。在测试之前执行
身体里的线条

请注意,即使flatter在index.html中运行良好,这也可能是它无法在本地服务器上运行的原因

在您的情况下,将所有与firebase相关的脚本(包括配置脚本)移动到
main.dart.js
脚本之前:


...
var firebaseConfig={
apiKey:“apiKey”,
authDomain:“我的app.firebaseapp.com”,
数据库URL:“https://myApp.firebaseio.com",
projectId:“我的应用程序”,
storageBucket:“我的app.appspot.com”,
messagingSenderId:“2243255670923”,
appId:“1:3134567819932:web:f09e90ce142l9ikk0d2f27”
};
firebase.initializeApp(firebaseConfig);

您好,谢谢您的回答。不幸的是,这不是问题所在。我在你提到的地方加入了这些脚本,我仍然得到同样的错误。我不明白为什么我需要包含它们,因为我最初没有它们,正如我所说的,如果我在Chrome上通过Android Studio运行该项目,它将完美工作。如果你能想出其他可能丢失的东西,请告诉我know@RedDeath你需要分享你的代码。如果不这样做,没有人能够有效地帮助你。甚至这个答案也是猜测。分享你的
index.html
和任何相关的firebase初始化代码。完全正确-我不认为这是必要的,但这是公平的。再次使用我的index.html文件更新了问题,请注意,index.html在从回答中指出的CMDA运行
flatter run
时运行良好,您是否将firebase脚本移到
main.dart.js
脚本之前?