Firebase auth CDN 不导出模块

Firebase auth CDN not exporting module

我按照官方 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>

我收到浏览器错误:

Uncaught SyntaxError: The requested module 'https://www.gstatic.com/firebasejs/9.4.1/firebase-auth.js' does not provide an export named 'auth'

取消对 auth 导入行的注释,你会得到与 firestore 导入行完全相同的错误。

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

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

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

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


    import { getAuth, signInWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/9.5.0/firebase-auth.js'
    
    const auth = getAuth();
    signInWithEmailAndPassword(auth, email, password)
      .then((userCredential) => {
        // Signed in 
        const user = userCredential.user;
        // ...
      })
      .catch((error) => {`enter code here`
        const errorCode = error.code;
        const errorMessage = error.message;
      });