我遵循谷歌官方教程的示例,通过CDN而不是SDK包含Firebase:
https://firebase.google.com/docs/web/alt-setup#from-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>
我收到浏览器错误:
未捕获的SyntaxError:请求的模块'https://www.gstatic.com/firebasejs/9.4.1/firebase-auth.js'不提供名为"auth"的导出
对auth导入行进行outcomment处理,而对firestore导入行则会得到完全相同的错误。
这是文件/教程的问题还是我的问题?
似乎教程引用了错误的文件?
看起来添加的代码示例是错误的。请尝试使用以下代码来使用针对web 的9+SDK版本
访问https://firebase.google.com/docs/auth/web/password-auth#sign_in_a_user_with_an_email_address_and_password
从'导入{getAuth,signInWithEmailAndPassword}https://www.gstatic.com/firebasejs/9.5.0/firebase-auth.js'const-auth=getAuth((;signInWithEmailAndPassword(身份验证、电子邮件、密码(.then((userCredential(=>{//登录时间const user=userCredential.user;//。。。}).catch((错误(=>{`在此处输入代码`const errorCode=错误代码;const errorMessage=error.message;})