firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.6k stars 361 forks source link

[Firestore] Cannot set properties of undefined (setting 'fromParams') #2498

Open jramosss opened 4 months ago

jramosss commented 4 months ago

[READ] Step 1: Are you in the right place?

Cloud Firestore support is provided by the @google-cloud/firestore library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the nodejs-firestore GitHub repo.

If you still think the problem is related to the code in this repository, then read on.

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

You can enable logging for Firestore by including the following line in your code:

admin.firestore.setLogFunction(console.log);

This will print Firestore logs to the console.

Relevant Code:

This is the trace i got by following the past point

Firestore (6.8.0) 2024-03-18T15:41:13.218Z QLnjt [Firestore._retry]: Retrying request that failed with error: TypeError: Cannot set properties of undefined (setting 'fromParams') at ClientPool.clientFactory (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/index.js:486:42) at ClientPool.acquire (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/pool.js:103:35) at ClientPool.run (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/pool.js:217:29) at MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/index.js:1391:30 at Firestore._retry (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/index.js:1251:30) at DocumentReader.fetchDocuments (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/document-reader.js:89:28) at DocumentReader.get (MYPATH/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/document-reader.js:52:9)

Basically there's a function that runs before starting my express.js app, that function just calls

myFunction().then(() => {
  app.listen(() => console.log('Server running on port 3000'))
})

The function calls

fs.collection('myCollection').get()

where fs is exported from other file that exports like this

import admin from 'firebase-admin'
export const fs = admin.firestore()
google-oss-bot commented 4 months ago

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

lahirumaramba commented 2 months ago
import admin from 'firebase-admin'
admin.firestore.setLogFunction(console.log);

The above seems to be working when I try to reproduce this issue.

Could you try with the modular imports to see if that helps?

import { setLogFunction } from 'firebase-admin/firestore'
setLogFunction(console.log);