Home > Back-end >  Firebase new Cloud Function throws INTERNAL error
Firebase new Cloud Function throws INTERNAL error

Time:12-12

Im working on a project in Vue.js 3 Typescript and Firebase. When trying to implement new cloud functions i suddenly encountered the following problem:

Failed to load resource: the server responded with a status of 500 ()

Unhandled Promise Rejection: FirebaseError: INTERNAL

My old Cloud Functions work just as expected, but trying to add one that deletes a document it suddenly occurred. I tried breaking it down thinking it was probably a syntactical problem, but even copying the whole boilerplate from another working cloud function did not help. Next i started to strip the function of its guts. Two things i discovered:

1. Barebones

exports.deleteSingleCourse = functions.region('europe-west1').https.onCall(async (data: any, context: any) => {

  console.log('teachersRef')
  return "teachersRef"
})

Output: {data: 'teachersRef'}

This code works as expected so there is no mistake when calling the function.

2. Just a little more

exports.deleteSingleCourse = functions.region('europe-west1').https.onCall(async (data: any, context: any) => {

  const teachersRef = db.collection(db, 'schools/'   'y70B7KSbwd2D55SRPItY'   "/teachers");
  console.log(teachersRef)

  return "test"
})

Output: Failed to load resource: the server responded with a status of 500 ()

Unhandled Promise Rejection: FirebaseError: INTERNAL

This code somehow already stops working entirely and throws the before mentioned error. Note: The console.log is only there to have used "teachersRef" variable in order to stop Firebase from cancelling the function deployment.

Just before this problem i accidentally had two different cloud functions in my index.ts with the same name and deployed them. I changed the names upon noticing, removed them from within the firebase console and re-deployed. I don't know if this could have anything to do with my problem but just wanted to mention it in case.

CodePudding user response:

With the Admin SDK version 8 you cannot use the modular syntax and you need to use the global admin namespace.

Therefore const teachersRef = db.collection(db, 'schools/' 'y70B7KSbwd2D55SRPItY' "/teachers");

must be changed to

const teachersRef = admin.firestore().collection('schools/' 'y70B7KSbwd2D55SRPItY' "/teachers");


If you want to use the modular syntax, you'll need to upgrade your Admin SDK version to version 10 and change the way you import it, as explained here in the doc.

  • Related