firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

Service database is not available with firebase 10.13 #8450

Closed GabrielRalph closed 1 month ago

GabrielRalph commented 2 months ago

Operating System

Mac OS

Environment (if applicable)

Chrome

Firebase SDK Version

10.133

Firebase SDK Product(s)

Auth, Database

Project Tooling

Vanila Javascript, VS Code Live Server

Detailed Problem Description

I have tried to retrieve the database object using the getDatabase method from "https://www.gstatic.com/firebasejs/10.13/firebase-database.js".

When the function is called it throws an error "Error: Service database is not available".

Down grading to the last version 10.12.5 fixes this bug, so I assume it was associated with the newest release.

Steps and code to reproduce issue

import {initializeApp} from 'https://www.gstatic.com/firebasejs/10.13/firebase-app.js' import {getAuth as _getAuth, signInWithRedirect as _signInWithRedirect, GoogleAuthProvider, onAuthStateChanged as _onAuthStateChange} from 'https://www.gstatic.com/firebasejs/10.13/firebase-auth.js' import {getDatabase as _getDatabase, child, push, ref as _ref, update, get, onValue, onChildAdded, onChildChanged, onChildRemoved, set, off} from "https://www.gstatic.com/firebasejs/10.13/firebase-database.js"

// Include this script in a html document and the error should occur

const CONFIG = {...}

const App = initializeApp(CONFIG); const Database = _getDatabase(App); const Auth = _getAuth();

export function getApp() {return App} export function getDatabase() {return Database} export function getAuth() {return Auth} export function ref(path) {return _ref(Database, path)} export function signInWithRedirect(provider) {return _signInWithRedirect(Auth, provider)} export function onAuthStateChanged(callback) {return _onAuthStateChange(Auth, callback)}

export {child, push, update, get, onValue, onChildAdded, onChildChanged, onChildRemoved, set, off, GoogleAuthProvider}

google-oss-bot commented 2 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

dlarocque commented 2 months ago

Hi @GabrielRalph, could you please try changing the versions from 10.13 to 10.13.0? I reproduced this and got the same error you did, and was able to fix it by doing this.

Firebase requires all the services being used to be the exact same version, and it seems that if we don't specify the patch version, it uses different versions for app and database, which causes this error. Locally, it was using version 10.13.0 for database, and 10.13 for app.

image

google-oss-bot commented 2 months ago

Hey @GabrielRalph. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 month ago

Hey @GabrielRalph. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 month ago

Since there haven't been any recent updates here, I am going to close this issue.

@GabrielRalph if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.