我試圖將我的javascript應用程式與firebase連接,我在firebase中創建了一個帳戶,我粘貼了我的配置,但它給了我3個錯誤:
意外的令牌“出口”;
不能在模塊外使用 import 陳述句;
firebase 未定義
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.8.3/firebase-firestore.js"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "<key>",
authDomain: "javascript-3bbaa.firebaseapp.com",
projectId: "javascript-3bbaa",
storageBucket: "javascript-3bbaa.appspot.com",
messagingSenderId: "<id>",
appId: "<appId>"
};
// Initialize Firebase
const firebase = initializeApp(firebaseConfig);
const db = firebase.firestore();
</script>
</body>
</html>
uj5u.com熱心網友回復:
嘗試這個:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js';
import { getFirestore, collection, getDocs } from 'https://www.gstatic.com/firebasejs/9.8.3/firebase-firestore-lite.js';
const firebaseConfig = {
apiKey: "<key>",
authDomain: "javascript-3bbaa.firebaseapp.com",
projectId: "javascript-3bbaa",
storageBucket: "javascript-3bbaa.appspot.com",
messagingSenderId: "<id>",
appId: "<appId>"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/495075.html
標籤:javascript
上一篇:如何僅附加節點的子節點?
