【问题标题】:Why getting Uncaught TypeError: Failed to resolve module specifier "firebase". Relative references must start with either "/", "./", or "../"?为什么会出现 Uncaught TypeError:无法解析模块说明符“firebase”。相对引用必须以“/”、“./”或“../”开头?
【发布时间】:2022-01-11 17:37:47
【问题描述】:

我已使用模块化代码将我的代码从 v8 版本转移到 v9 版本,但尽管安装了汇总包,但仍出现此错误。 我的 JS 代码:

<script type="module">
      // TODO: Add SDKs for Firebase products that you want to use
      // https://firebase.google.com/docs/web/setup#available-libraries
      import firebase from 'firebase';
      import { initializeApp } from "firebase/app"
      import { getAuth, onAuthStateChanged } from "firebase/auth";
      import { getDatabase } from "firebase/database"
      // Your web app's Firebase configuration
      const firebaseConfig = {
      //app config
      };

      // Initialize Firebase
      const firebaseApp = initializeApp(firebaseConfig);
      const db = getDatabase(firebaseApp);
      const auth = getAuth(firebaseApp);
    </script>

我得到的错误:未捕获的类型错误:无法解析模块说明符“firebase”。相对引用必须以“/”、“./”或“../”开头

我花了相当长的时间,但无法找到问题。

【问题讨论】:

标签: javascript firebase firebase-realtime-database module firebase-authentication


【解决方案1】:

我也有类似的错误。我像这样解决了这个错误。

import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-app.js'
import { getAuth } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-auth.js'

我认为你可以使用这些网址。

我不确定这是正确的方法。

【讨论】:

    【解决方案2】:

    据我了解,firebase 9 的很大一部分是您不再需要导入整个 firebase,现在只需导入您需要的任何模块。

    因此你不需要

    import firebase from 'firebase';
    

    尝试不导入“firebase”,看看会发生什么

    【讨论】:

    • 删除该行后仍然出现相同的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多