【问题标题】:Firebase auth CDN not exporting moduleFirebase auth CDN 未导出模块
【发布时间】:2021-12-01 14:41:13
【问题描述】:

我正在按照 Google 官方教程示例通过 CDN 而不是 SDK 包含 Firebase:

https://firebase.google.com/docs/web/alt-setup#from-the-cdn

逐字复制示例后:

<body>
  <!-- Insert this script at the bottom of the HTML, but before you use any Firebase services -->

  <script type="module">
    import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js'

    // If you enabled Analytics in your project, add the Firebase SDK for Google Analytics
    import { analytics } from 'https://www.gstatic.com/firebasejs/9.4.1/firebase-analytics.js'

    // Add Firebase products that you want to use
    import { auth } from 'https://www.gstatic.com/firebasejs/9.4.1/firebase-auth.js'
    import { firestore } from 'https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js'
  </script>
</body>

我收到浏览器错误:

未捕获的语法错误:请求的模块 'https://www.gstatic.com/firebasejs/9.4.1/firebase-auth.js' 没有 提供一个名为“auth”的导出

去掉 auth import 行,你会得到与 firestore 导入行完全相同的错误。

这是文件/教程的问题还是我的问题?

似乎教程引用了错误的文件?

【问题讨论】:

    标签: firebase module cdn missing-features


    【解决方案1】:

    看起来添加的代码示例是错误的。请尝试使用以下代码来使用 9+ 版本的 Web SDK

    访问https://firebase.google.com/docs/auth/web/password-auth#sign_in_a_user_with_an_email_address_and_password

    从“https://www.gstatic.com/firebasejs/9.5.0/firebase-auth.js”导入 { getAuth, signInWithEmailAndPassword } const auth = getAuth(); signInWithEmailAndPassword(身份验证,电子邮件,密码) .then((userCredential) => { // 登录 常量用户 = userCredential.user; // ... }) .catch((error) => {`在此输入代码` 常量错误代码 = 错误代码; 常量 errorMessage = error.message; });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 2022-11-13
      • 2019-01-15
      • 2020-11-17
      • 1970-01-01
      • 2018-11-16
      • 2021-08-15
      相关资源
      最近更新 更多