admin管理员组文章数量:1314442
I am trying to access my realtime database in firebase but it shows me this error Uncaught Error: Service database is not available
. I have searched for what this could posabbly mean but I couldn't find anything useful or a solution.
Here is my code:
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 ".6.4/firebase-app.js";
import { getAnalytics } from ".6.4/firebase-analytics.js";
import { getDatabase, ref, set } from ".1.0/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
//
// 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: The script type is set to modular.
Do you know what the error means and what is happening?
I am trying to access my realtime database in firebase but it shows me this error Uncaught Error: Service database is not available
. I have searched for what this could posabbly mean but I couldn't find anything useful or a solution.
Here is my code:
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./firebasejs/9.6.4/firebase-app.js";
import { getAnalytics } from "https://www.gstatic./firebasejs/9.6.4/firebase-analytics.js";
import { getDatabase, ref, set } from "https://www.gstatic./firebasejs/9.1.0/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google./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: The script type is set to modular.
Do you know what the error means and what is happening?
Share Improve this question edited Jan 23, 2022 at 14:57 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges Recognized by Google Cloud Collective asked Jan 23, 2022 at 14:32 Jerry LinJerry Lin 1352 silver badges10 bronze badges 2-
1
I don't think it's the cause of the problem, but I'd update the
database
import to version9.6.4
too, so that the all Firebase SDK versions are the same. – Frank van Puffelen Commented Jan 23, 2022 at 14:58 - Thanks that worked. Can you add that as an answer? – Jerry Lin Commented Jan 23, 2022 at 18:14
2 Answers
Reset to default 9You're using difference versions of the Firebase SDKs. I'd update the database import to version 9.6.4 too, so that the all Firebase SDK versions are the same.
Deleting node_modules and package-lock.json followed by an npm install
helped me resolve a similar issue just now. Sharing here in case it's helpful to anyone.
This one is particularly obscure given it's not actually related to any specific code changes.
本文标签: Uncaught Error Service database is not available firebase javascriptStack Overflow
版权声明:本文标题:Uncaught Error: Service database is not available firebase javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741969584a2407753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论