-
Notifications
You must be signed in to change notification settings - Fork 893
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
Database tries to call connectDatabaseEmulator when already initialized, leading to FIREBASE FATAL ERROR #6853
Comments
@Janque - can you provide an example of how you're using RTDB with Next.js? |
If I understand this correctly, the recommendation from @Janque is to modify the For general housekeeping, I'm going to remove the firestore tag from this issue. |
Well, as I said it's not really an issue with a specific use, but rather the initialization. Here is an simplified bit that also triggered the error: // pages/index.js
import { incrementCount } from '../firebase/database';
export default function Home(props) {
//...
}
export async function getServerSideProps() {
await incrementCount();
return {props:{
//...
}}
}
// firebase/firebase.js
//...
export const firebaseApp = initializeApp(firebaseConfig);
export const database = getDatabase(firebaseApp);
//...
// firebase/database.js
import { database } from './firebase';
import { ref, set, increment } from "firebase/database";
export async function incrementCount() {
await set(ref(database, "count"), increment(1));
return;
} After I run |
Yes |
@Janque - thanks for the example. I just wanted to make sure there wasn't a |
@maneesht it's 13.0.2, but I just updated to 13.0.6 and it still happens. Start the emulators, all fine; edit and save a file like index.js; if the browser didn't reload by it self, I refresh the page and then the error.
|
I just did the change that I suggested in my local package files and the problem is temporarily solved // node_modules/@firebase/database/dist/node-esm/index.node.esm.js
function getDatabase(app = getApp(), url) {
const db = _getProvider(app, 'database').getImmediate({
identifier: url
});
if (!db._instanceStarted) {
const emulator = getDefaultEmulatorHostnameAndPort('database');
if (emulator) {
connectDatabaseEmulator(db, ...emulator);
}
}
return db;
} |
@Janque I was able to reproduce the issue. Though the problem is a little more complicated than I originally had thought. The error comes from the |
@maneesht I never call |
That's very odd, do you have environment variables set up for your emulator port? |
Not sure what you mean by "for the emulator port", but I don't have any .env files |
Basically, I appreciate your patience. The more information I know about your use-case, the better the subsequent tests will be. |
Well I don't have any .env setup. So I guess no. I only have the emulators config in the firebase.json "emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"database": {
"port": 9000
},
"hosting": {
"port": 5002
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
} I'd maybe mention that the default hosting port was 5000 and I had to change it because some AirPlay feature (I think) uses it. Also when I run the emulators I use |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
I'm using the nextjs integration with firebase database and when there is a hot reload (ex. saving a file), the following error appears: Error: FIREBASE FATAL ERROR: Cannot call useEmulator() after instance has already been initialized.
From the line:
When there has been no hot reload, everything works fine.
After more investigation I found that the code that connects the emulator differs from the one that connects the firebase emulator
I believe that those changes would fix the issue.
My package.json dependencies
The text was updated successfully, but these errors were encountered: