Unexpected INTERNAL error encountered with Firebase's Cloud Function update

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.

Answer №1

When utilizing Admin SDK version 8, it is not possible to utilize the modular syntax and you must instead use the global admin namespace.

Therefore, the code snippet

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

needs to be updated to

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


If you wish to implement the modular syntax, you will have to upgrade your Admin SDK to version 10 and modify how you import it, as detailed here in the documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a merged object from a split string array in TypeScript

I possess an array containing objects structured as follows; const arr1 = [ {"name": "System.Level" }, {"name": "System.Status" }, {"name": "System.Status:*" }, {"name": "System.Status:Rejected" }, {"name": "System.Status:Updated" } ] My object ...

Is it possible to record the attributes within an interface in TypeScript?

Imagine I have the following scenario: interface Validator { validate: (value: string) => boolean; errorMessage: string; } interface EditDialogField { label: string; prop: string; required?: boolean; type: 'input'; validators?: ...

Receiving a blank array from the firestore database

I have written a code for the LeftBar Component where I am trying to retrieve data stored in the "contacts" document in Firebase. However, I am getting an empty array and I'm not sure why this is happening. Additionally, I would like to know how to ac ...

If every single item in an array satisfies a specific condition

I am working with a structure that looks like this: { documentGroup: { Id: 000 Children: [ { Id: 000 Status: 1 }, { Id: 000 Status: 2 ...

Display different content based on the item selected in a listbox using headless UI and Vue.js

We are encountering an issue with the Listbox component from HeadlessUI. The problem is that we are unable to display content based on the selected option in the listbox. Here is the code for the listbox: <Listbox v-model="selectedElement"> ...

How can I implement a Vue v-if directive in App.vue, while having a toggle button in a separate component?

I am facing an issue in my App.vue file where I have a v-if condition that is hiding a div when the data returns false. I want to implement a toggle functionality for this, but I would like to place the button in a different component that is imported into ...

Error message: "Angular requires either importing or local installation"

For my ionic application development, I encountered an issue while trying to link pages together in the ionic creator. The error message on the .ts file is: typescript: src/pages/home/home.ts, line: 4 Individual declarations in merged declar ...

Tips for preventing event propagation while clicking on a swiper.js image next/prev button within a bootstrap card

I have integrated ngx-swiper-wrapper within a bootstrap card as shown below, with a routerlink at the top. When I click anywhere on the card, it successfully routes to the designated page. However, I am facing an issue where I want to prevent routing if a ...

Is it possible to alter the name of a slot before displaying the element in the shadowDOM, depending on the slot utilized in the DOM?

In my project, I am working on implementing different features for both desktop and mobile devices. Some of these features can be replaced by slots. My goal is to have a slot that can be either replaced by a desktop slot called poster-foreground, or a mobi ...

Error in TypeScript when accessing object using string variable as index

Currently, I am facing a challenge in my project where I am dynamically generating routes and managing them in an Elysia(~Express) application. The issue arises when TypeScript's type checking system fails to index an object using a string variable. S ...

Is there a way to determine the specific child property types of a custom Generic type extension?

I am looking to create a function that can retrieve a property from an extended generic type. Is this something achievable? Here is my attempt: interface Animal { readonly weight: {total: number} } interface Dog extends Animal { readonly weight: ...

understanding the life cycle of components in Ionic

I created a component with the following structure: export class AcknowledgementComponent implements AfterViewInit { private description: string; @Input('period') period: string; constructor() { } ngAfterViewInit() { console.log ...

The specified type 'IterableIterator<number>' does not belong to either an array type or a string type

Encountering an error while attempting to generate a dynamic range of numbers. Error: Type 'IterableIterator<number>' is not recognized as an array or string type. Use the compiler option '--downlevelIteration' to enable iteratio ...

Using TypeScript to return an empty promise with specified types

Here is my function signature: const getJobsForDate = async (selectedDate: string): Promise<Job[]> I retrieve the data from the database and return a promise. If the parameter selectedDate === "", I aim to return an empty Promise<Job[] ...

I am encountering problems with images that are imported as module imports in a Vue.js project

Currently, I have stored all the default images for my Vue project in a designated folder. The path to this folder is web/images/defaults/<imageNames>.png. Instead of importing each image individually in my components, I wish to create a file that co ...

Integrate jQuery into a Vue.js 2 project using the expose-loader plugin

For my latest Vue.js project using the vue-cli, I attempted to import jQuery with expose-loader. Following the instructions in the official documentation, but unfortunately, I was not successful. Here are the steps I took: Installed jQuery and expose- ...

Understanding the useQuasar() function in Pinia store file with VueJS

I've encountered an issue in my VueJS + Quasar project where I'm trying to utilize useQuasar() in my store file gallery.js, but it keeps returning undefined. A similar problem arose when I was attempting to access useRouter(), however, I managed ...

Different custom background images for every individual page in Nuxt

Looking for a unique background-image for each page in my app is proving to be challenging. Currently, I have defined the background-image in style/app.scss. @import 'variables'; @import 'page_transition'; @import url('https://f ...

Adding an object to a list in Android using Firebase Database

Managing a list of comments within an object can be tricky when trying to add new comments without affecting the existing ones. I've successfully used transactions in the past for efficiently editing integers, but I'm unsure if the same approach ...

"Exploring the world of Ionic 2: uncovering its public variables

I'm facing an issue with Ionic 2, specifically with Angular. My concern revolves around a variable called "isConnected". I am unable to access it from an internal function within a function as it gives me an error saying "can't define property of ...