Currently, I am immersed in a project involving Vue.js 3, Typescript, and Firebase. However, while attempting to integrate new cloud functions, I came across an unexpected issue:
Failed to load resource: the server responded with a status of 500 ()
Unhandled Promise Rejection: FirebaseError: INTERNAL
Interestingly, my existing Cloud Functions are working flawlessly. Yet, upon trying to add one that is meant to delete a document, this problem arose out of nowhere. Initially, I suspected a syntax error but even after copying the entire template from a functioning cloud function, the issue persisted. In an attempt to troubleshoot, I decided to simplify the problematic function. Here's what I discovered:
1. Basic Structure
exports.deleteSingleCourse = functions.region('europe-west1').https.onCall(async (data: any, context: any) => {
console.log('teachersRef')
return "teachersRef"
})
Output: {data: 'teachersRef'}
This simplistic code executed successfully, indicating that there was no mistake during the function call.
2. Adding Complexity
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
To my surprise, this piece of code ceased functioning entirely, triggering the previously mentioned errors. It's worth noting that the console.log statement was purposely included to utilize the "teachersRef" variable, preventing Firebase from halting the deployment of the function.
Prior to encountering this setback, I inadvertently deployed two distinct cloud functions with identical names in my index.ts file. Upon realization, I promptly renamed them, removed them via the Firebase console, and re-deployed. While uncertain if this event is related to my current issue, I felt it was important to mention just in case.