我正在從 CDN 匯入 Firebase Firestore 以在本地服務器上運行。我按照檔案中的說明匯入了它,就在這里:https ://firebase.google.com/docs/web/alt-setup
我的代碼:
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js';
import { getAuth, createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/9.0.0/firebase-auth.js';
import { firestore } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-firestore.js'
問題:Firebase 應用程式和 Firebase 身份驗證已匯入并且運行良好,但是 Firestore 沒有被匯入。我收到此錯誤:
Uncaught SyntaxError: The requested module 'https://www.gstatic.com/firebasejs/9.6.3/firebase-firestore.js' does not provide an export named 'firestore'
這是我第一個使用 firebase 的 web 專案,我不知道如何前進。這個新手將不勝感激任何幫助或建議。如果您需要更多資訊,請告訴我,謝謝。
uj5u.com熱心網友回復:
我認為來源已被棄用。原因是這樣寫的解釋,來自這個來源https://firebase.google.com/docs/web/alt-setup#from-the-cdn
對于大多數 Firebase Web 應用,我們強烈建議通過 npm 使用 SDK 版本 9。
我找到了兩種方式,在版本 8 中你仍然可以使用這種方式。
<body>
<!-- Insert this script at the bottom of the HTML, but before you use any Firebase services -->
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js"></script>
</body>
但是如果你想在版本 9 中使用,你必須使用 npm。
npm install firebase@9.4.1 --save
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
您可以訪問:https ://firebase.google.com/docs/firestore/quickstart#web-version-9
希望這可以幫助你。
uj5u.com熱心網友回復:
你有沒有在腳本標簽中輸入這個
<body>
<script type="module">
// ...
// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
// ...
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
</script>
</body>
type=module ?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/412208.html
標籤:
