The inclusion of googleapis prevents the uploading of the cloud function

I am facing an issue with my Google Cloud Functions project. Whenever I include the googleapis library to authenticate and access the Play Developer API, the deployment of the project fails. Below is a simplified version of my code:

import * as functions from 'firebase-functions';
import * as serviceAccountPlay from './service-account.json'; 
import { google } from 'googleapis';

export const realtimeNotificationListener = 
functions.pubsub.topic('billing_information').onPublish(async (data, context) => {
    //Deploy fails when this part is included. Removing this allows successful deployment.
    const authClient = new google.auth.JWT({
       email: serviceAccountPlay.client_email,
       key: serviceAccountPlay.private_key,
       scopes: ["https://www.googleapis.com/auth/androidpublisher"]
    })
    const playDeveloperApiClient = google.androidpublisher({ 
       version: 'v3',
       auth: authClient}
    );
    const developerNotification = data.json;
    console.log('Received realtime notification: ', developerNotification);
    try {
      const subscription = await playDeveloperApiClient.purchases.subscriptions.get({
          packageName: developerNotification.packageName,
          subscriptionId: developerNotification.subscriptionNotification!.subscriptionId,
          token: developerNotification.subscriptionNotification!.purchaseToken
      });
      console.log('Received purchase information: ', subscription)
    } catch (error) {
    console.error(error);
}
})

The package.json file includes this line in the dependencies section:

"googleapis":"^94.0.0"

I attempted deployment using the command:

firebase --debug deploy --only functions:realtimeNotificationListener

The debug output provided little insight:

[2022-02-01T11:57:02.767Z] Error: Failed to update function playSubBilling-realtimeNotificationListener in region us-central1 at C:\Users-\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:38:11 at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Fabricator.updateV1Function (C:\Users-\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:255:32) at async Fabricator.updateEndpoint (C:\Users-\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:136:13) at async handle (C:\Users-\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:75:17)

EDIT Upon installing googleapis in the /functions folder, I encountered numerous other errors:

After running npm i googleapis --save, I faced:

https://i.sstatic.net/nsBIf.png

Following npm audit fix, I got:

https://i.sstatic.net/CLEKr.png

Lastly, upon executing

firebase --debug deploy --only functions:realtimeNotificationListener
, I received:

https://i.sstatic.net/odO2p.png

What modifications should I make to get my project up and running again?

EDIT 2

Solution was found by using: npm audit fix --force and npm update

Answer №1

The root of this issue appears to stem from the incorrect installation of dependencies in a specific directory.

When developing a Firebase Function, it is imperative that all necessary dependencies are installed within the /functions directory.

In your case, the

"googleapis":"^94.0.0"
dependency must be included in the package.json file located in the /functions directory rather than the main project folder. To address this, I suggest navigating to the /functions directory and executing the following command:

npm i googleapis --save

Typically, the package-lock.json file should update automatically after installing a new dependency. However, if this does not occur, you can rectify the situation by generating a new lock file that will replace the existing one through the use of the command below:

npm i --package-lock-only

For further insights on this approach, refer to this resource here.

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

Discover the offsetTop value of a child element in React using TypeScript

How can I retrieve the offsetTop of React children in Typescript? Here is an example of my component: export default class FadeIn extends Component { private onScroll = () => { React.Children.forEach(this.props.children, child => { // G ...

Adjusting the background opacity when the sidebar is open in a React + Typescript project

I am currently working on customizing a sidebar using the react-pro-sidebar library along with React and Typescript. The sidebar layout seems to be in order, but I am facing difficulty in adjusting the background color of the rest of the screen when the si ...

The TypeScript, NextJS project is encountering an issue where it is unable to read the property 'cwd' due to a TypeError

I've noticed this particular error popping up frequently online, but it's not quite matching the issue I'm facing. Every time I execute yarn dev, I encounter the following error: next-dev.js?53bc:89 Error was not caught TypeError: Cannot re ...

Bring in a template in TypeScript with no need for require statement

Currently, I'm utilizing TypeScript along with Angular 1.5 component. In my scenario, I have a custom decorator in place through which I send templates via require function. The setup is functional; however, I am consistently receiving a tslint warnin ...

Navigating with Gatsby Link and leveraging TypeScript

I am currently utilizing Gatsby Link with TypeScript and I am looking to pass parameters to a linked component from the source component. The documentation provided by Gatsby states the following: Sometimes you’ll want to pass data from the source pag ...

Although there may be some issues with tslint, the functionality is operating smoothly

I am in the process of learning tslint and typescript. Currently, I am facing an issue that I need help with. Could you provide guidance on how to resolve it? Despite conducting some research, I have been unable to find a solution. The relevant code snippe ...

Issues arise when attempting to utilize Async/Await with a gRPC method

Here is the code snippet used to initialize a gRPC server: export const initServer = async (finalPort: number): Promise<string> => { let initStatus = 'initial'; gRPCserver.addService(webcomponentHandler.service, webcomponentHandler.h ...

Ionic 2 - Error: Module ""."" not found at runtime

Encountered a perplexing error while running my Ionic 2 application on localhost using the command: ionic serve I've diligently inspected all my imports for any incorrect paths in my TypeScript files, but haven't found anything amiss. The only ...

Universal categories, limitations, and hereditary traits

As a newcomer to Typescript and generics, I am unsure if I have encountered a bug/limitation of Typescript or if I am missing the correct approach to achieve my desired outcome. I have a base class called Widget which is generic and holds a value of type ...

Accessing JSON data stored locally and initializing it into a TypeScript variable within a React application

I'm new to working with JSON arrays and I'm facing a challenge. I am looking for a way to load data from a JSON file into a Typescript variable so that I can perform a specific operation that involves arrays. However, I'm unsure of how to ac ...

Problem with ngStyle: Error indicating that the expected '}' is missing

I encountered an error in the Chrome console when trying to interpret the code below: <div [ngStyle]="{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat&ap ...

remove an offspring item from an array assembly

I have a variable called today that stores data retrieved from an API. I'm attempting to delete some information from it using a function, but I keep encountering the error message Cannot read property 'id' of undefined. SAMPLE DATA [ ...

Personalized style for text overflow property

The application is created using Angular. Within a component, we have a div containing some text: <div>abcdefghijklmnop<div> Depending on the screen size, the text should either be fully displayed or clipped. I discovered the property 'te ...

What is the correct way to implement ramda's ifElse function in typescript?

My attempt to enhance the typing of ifElse in Ramda, which currently has a type definition as follows: export function ifElse(fn: Pred, onTrue: Arity2Fn, onFalse: Arity2Fn): Arity2Fn; However, I quickly reached the limitations of TypeScript (or rather my ...

Retrieve the output of forkJoin subscription in Angular 6 using rxJs 6

A Straightforward Example: const tasks = []; for (let i = 0; i < this.initialData.length; i++) { tasks.push( this.taskService.getDetails(this.id1[i], this.id2[i]) }; combineLatest(...tasks).subscribe(taskGroup => { console.log(task ...

What is the most effective method for waiting for multiple requests to complete?

I am working on a component that requires fetching data from multiple endpoints through independent API calls. I want to make all these calls simultaneously and only load the user interface once all the data has been fetched successfully. My approach invo ...

What is the reason for not being able to pass props while utilizing "input type" in React with Styled-components?

Currently, I am delving into the world of React. I am trying to implement styled-components in order to style my "input" elements. While I can easily extend props with a normal input, things get tricky when it comes to using styled-components... The props ...

Issue with Typescript: conditional return type failing to function

I am working with a function that has its return type determined by the arguments provided. const example = (flag: boolean): typeof flag extends true ? "yes" : "no" => { if (flag === true) { return "yes" } else { ...

Ways to receive one of two variations

Dealing with different cases for type is my current challenge. In a React Functional Component, I have a callback function property that accepts an argument of either string or number. interface InputProps { getValue?: (value: string | number) => vo ...

Guide on implementing Regular Expressions in Directives for validation in Angular 8

Managing 8 different angular applications poses its unique challenges. In one of the applications, there is a directive specifically designed for validating YouTube and Vimeo URLs using regular expressions. Unfortunately, once the RegExp is declared, ther ...