Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Service database is not available #6388

Closed
HaoboZ opened this issue Jun 26, 2022 · 13 comments
Closed

Error: Service database is not available #6388

HaoboZ opened this issue Jun 26, 2022 · 13 comments
Assignees

Comments

@HaoboZ
Copy link

HaoboZ commented Jun 26, 2022

[REQUIRED] Describe your environment

  • Operating System version: Windows
  • Browser version: Edge
  • Firebase SDK version: 9.8.4
  • Firebase Product: database

[REQUIRED] Describe the problem

Steps to reproduce:

When using the database with const db = getDatabase( app ); I get the error Error: Service database is not available.
Running using NextJS, happens on build if placed outside components, happens on client side if placed in useMemo. This works with 9.8.1 and stopped working when upgrading firebase package.

Relevant Code:

@maneesht
Copy link
Contributor

maneesht commented Jun 27, 2022

Hi @HaoboZ, I am unable to reproduce this. Do you have a minimal reproducible example? I tried running:

const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const Home = () => <div>Home</div>;

and didn't have any problems.

@jbalidiong jbalidiong added the v9 label Jun 27, 2022
@HaoboZ
Copy link
Author

HaoboZ commented Jun 29, 2022

Was trying to reproduce it, but after updating packages again it seems to work now? Downgrading to 9.8.3 seems to still have the problem, but the latest version seems to be fine now.

@HaoboZ HaoboZ closed this as completed Jun 29, 2022
@HaoboZ HaoboZ reopened this Jul 9, 2022
@HaoboZ
Copy link
Author

HaoboZ commented Jul 9, 2022

@maneesht I just got this again, here's a reproduction of it https://github.com/HaoboZ/firebase-db-test.
You need to copy env.template to env and fill out the info.

@HaoboZ HaoboZ changed the title Can't use database with NextJS Error: Service database is not available Jul 9, 2022
@maneesht maneesht self-assigned this Jul 11, 2022
@maneesht
Copy link
Contributor

maneesht commented Jul 11, 2022

@HaoboZ I was able to reproduce this issue and it seems like database is the only product affected. We are looking into this. It seems to be isolated to 9.9.0. For the time being, can you use 9.8.4?

@HaoboZ
Copy link
Author

HaoboZ commented Jul 11, 2022

Sounds good! Its such a weird bug since it failed when I just started using 9.8.4 as well, but afterwards, it worked, maybe because of a dependency?

@maneesht
Copy link
Contributor

The interesting thing here is that I tried removing pnpm as the package manager and just used yarn and everything worked fine, regardless of the version. However, I created a new nextjs repo with pnpm and couldn't reproduce the issue. Still looking into this.

@hsubox76
Copy link
Contributor

This sounds like the sort of issue you get when there are multiple versions of @firebase/database (or multiple versions of app) getting initialized somehow. It's also possible that during an update the package manager might have got mixed up and kept duplicate versions around. Doing npm ls @firebase/database (when the local repo is in the broken state) should show if that's the case.

Another thing to check is maybe a console.log() to see if initializeApp() is being called more than once. I notice a lot of people put initializeApp() inside a conditional (if (getApps().length === 0)) when they have hot reloading apps or apps that could call the code more than once.

@maneesht
Copy link
Contributor

@hsubox76 you're right. There are two resolved versions of @firebase/app. @HaoboZ please use @firebase/app@0.7.28 instead of @firebase/app@0.7.27.
image

@HaoboZ
Copy link
Author

HaoboZ commented Jul 13, 2022

I see, this seems like a problem of the packageExtensions for it to work with yarn PnP. Is there a way for this to resolve automatically? Without the packageExtensions, it will never build since it says auth and database needs app as dependencies, and with it, it won't update correctly.

@maneesht
Copy link
Contributor

I applied the changes mentioned in my previous comment and left your packageExtensions as-is and it worked. In addition, the default setup created by create-next-app works fine without any extra yarn configuration.

@HaoboZ
Copy link
Author

HaoboZ commented Jul 14, 2022

the default create-next-app uses yarn without PnP. If you use PnP, it throws an error when trying to run it that says module not found, where I found a somewhat solution here #3707. However, it seems that if a new version comes out and you update firebase in package.json, it will not update those versions that were installed by yarnrc.yml.

@maneesht
Copy link
Contributor

pnpm create next-app --ts actually allows you to use pnpm as your package manager

@maneesht
Copy link
Contributor

I'm going to go ahead and close this, as it seems like the original issue has been resolved.

@firebase firebase locked and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants