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