Firebase Database (${JSCORE_VERSION}) INTERNAL ASSERT FAILED: Unknown node type
Operating System
Mac M1
Browser Version
Chrome/121.0.6167.139 (Official Build) (arm64)
Firebase SDK Version
^10.8.0
Firebase SDK Product:
Database
Describe your project's tooling
NextJS default bundler
Describe the problem
When firebase initialization logic is seperated into a seperate package, and imported, an error occurs with realtime database listeners. This issue as far as i know only occurs with the realtime database listeners ie. onChildAdded, onValue, and doesnt occur with eg. get, or any other service, eg. firestore. Additionally, it only occurs when seperated, built, and imported. If i define the initilization logic directly in the nextjs app, it works as expected. Furthermore, this only occurs when I have 2 conditions on the query, eg. limitToFirst(5) AND orderByChild("updatedAt"), if only one is present, the error is not triggered (although there is another weird issue if only limitToFirst is set, then onChildRemoved is triggered immediately after onChildAdded, even though it shouldnt be, but regardless, this is less important).
Note I have been using this strategy of building the initilization logic in a seperate package and importing it for a while. This only started occuring when I try to do what is described: toggle a realtime database listener with two QueryConstraint's
Steps and code to reproduce issue
https://github.com/ljrahn/firebase-unknown-node-type
- Clone the repo:
[email protected]:ljrahn/firebase-unknown-node-type.git -
npm install -
npm run build:functions -
npm run build:deps -
npm run dev - Open
http://localhost:3000. - Click
Add Data! - Error
Error: Firebase Database (${JSCORE_VERSION}) INTERNAL ASSERT FAILED: Unknown node typeshould occur. - Experience pain...
Note in ./src/pages/index.tsx we are importing import { initializeFirebase } from "../../deps/build/firebase". if this is changed to import { initializeFirebase } from "../../deps/firebase", the error disapeers, and we fetch the data as expected.
facing same issue when used in Vue3 project. Here in my case i am having multiple listener on the same path, eg: childChanged, childRemoved. It works when one of the listener is commented.
Thanks for the repro. Just a quick note before fully looking into it - adding a couple of missing steps that are needed to fully repro:
Steps and code to reproduce issue
https://github.com/ljrahn/firebase-unknown-node-type
- Clone the repo:
[email protected]:ljrahn/firebase-unknown-node-type.gitnpm install
also cd functions and npm install there
npm run build:functionsnpm run build:deps
Start the emulator with npm run emulator - this requires that you have the Firebase CLI installed (npm install -g firebase-tools if not)
npm run dev- Open
http://localhost:3000.- Click
Add Data!- Error
Error: Firebase Database (${JSCORE_VERSION}) INTERNAL ASSERT FAILED: Unknown node typeshould occur.- Experience pain...
The problem is that you are importing 2 separate bundles of firebase/database. You have imports from firebase/database in both index.tsx and in deps/build/firebase.js (generated file). Unfortunately, when you build deps/build/firebase.js, you have the tsconfig "module" set to "NodeNext", so it outputs a commonjs file with require statements. This causes it to import the CJS bundle of @firebase/database. Meanwhile, your index.tsx is a standard ESM file with import statements, so it's importing the ESM bundle of @firebase/database. This means there's two copies of the code, and the corresponding internal classes, so when it does an "instanceof" check for some data, it fails when it should succeed, because there's 2 copies of the class and it's checking the wrong copy.
It works when you import from "deps/firebase" instead because now you're using the TS ESM source file with "import" statements, so it brings in the same bundle of firebase/database as index.tsx does.
A quick fix is to change your deps/tsconfig.json file from "module: NodeNext" to "module: ES2020". I did this and it fixed the bug. Another option is to not build deps separately and import from deps/firebase.ts directly. It's not clear to me why that extra build step is necessary but I don't know the context of your project architecture so that's up to you. In any case, if you do want to build it, make sure the built artifact is in the same format (ESM) as your main project.
facing same issue when used in Vue3 project. Here in my case i am having multiple listener on the same path, eg: childChanged, childRemoved. It works when one of the listener is commented.
I would also check if you are importing firebase/database in multiple parts of your project that are treated differently (some are require, some are import, some are built separately, etc)
It seems like this isn't a bug in the Firebase SDK but I would like verification that this fixes the issue for everyone, so I'll leave it open with the needs-info tag where the bot will close it in 10 working days if no one replies.
Hi @hsubox76 , we have a micro-frontend application, where ,in both the services, we import firebase/database. is this an issue? We are trying to use the firebase DB reference from main-ui, and use the same DB refrence it in our service, so that i don't have to re-authenticate again in our service. However sdk methods are imported separately in both the service These 2 services are built separately. any workaround you would like to suggest?
Hi @suhail23599,
If I understand correctly, this might be the use case for FirebaseServerApp. It can be initialized with an Auth Token created from a user session on a client. You will need to send the Auth token to your service, where It will to sign-in the user in your application's backend to perform user-context (ie: not admin context) operations, such as the use of RTDB. We've added it to the SDK to support SSR Frameworks, which have both client and server-side rendering phases.
Hey @ljrahn. 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!
Since there haven't been any recent updates here, I am going to close this issue.
@ljrahn 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.
We resolved this issue by importing firebase SDK methods only in one service, ie. in our case it was a parent ui, then we exposed all these methods to child UI. For anyone who is having this issue, can try this approach, Good luck!