我正在尝试访问 firebase 中的实时数据库,但它向我显示此错误
Uncaught Error: Service database is not available
。我已经搜索过这可能意味着什么,但我找不到任何有用的东西或解决方案。
这是我的代码:
window.addPerson = addPerson;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const userVar = urlParams.get('user')
const userVarSplitted = userVar.split('#')
const userVarFormatted = userVarSplitted[0] + ":" + userVarSplitted[1]
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-analytics.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.1.0/firebase-database.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
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {MY FIREBASE CONFIG};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
if (app.length === 0) {
console.log("no firebas app")
}else{
console.log("initialized")
}
const analytics = getAnalytics(app);
const database = getDatabase(app);
function addPerson() {
set(ref(database, "verified/" + userVarFormatted), {
name: userVarSplitted[0],
discriminator: userVarSplitted[1]
});
console.log("added")
PS:脚本类型设置为模块化。
您知道错误意味着什么以及发生了什么吗?
您使用的是不同版本的 Firebase SDK。我也将数据库导入更新到版本 9.6.4,以便所有 Firebase SDK 版本都相同。
删除node_modules和package-lock.json,然后加上
npm install
帮助我解决了刚才的类似问题。在这里分享,以防对任何人有帮助。
这个问题特别晦涩,因为它实际上与任何代码更改都不相关。