Issue
I have a google cloud functions project and once I include the googleapis to authorize to play developer api I cannot deploy the project anymore. This is the mwe:
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) => {
//With this it does not deploy. Removing this deploys successfully
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);
}
})
I have this line in my package.json dependenies section: "googleapis":"^94.0.0"
I deployed using this command firebase --debug deploy --only functions:realtimeNotificationListener
The debug output is not very helpful:
[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
After installing googleapis in the /functions
folder I get a whole lot of other errors:
After npm i googleapis --save
I get:
After npm audit fix
I get:
And after firebase --debug deploy --only functions:realtimeNotificationListener
I get:
What do I have to change to get this running again?
EDIT 2
Fixed it with
npm audit fix --force
and
npm update
Solution
This issue seems to be caused by not installing the dependencies in the correct directory.
When writing a Firebase Function all of its dependencies should be installed in the /functions
directory.
For your specific situation the "googleapis":"^94.0.0"
dependency should be added to the package.json
in the /functions
directory, not the main project one. To solve this I recommend going to the /functions
directory and running the command:
npm i googleapis --save
The package-lock.json
should be updated automatically when installing a dependency, but if it doesn't you can create a new one which will overwrite the old one by running this command :
npm i --package-lock-only
More info about this command can be found here.
Answered By - Lluís Muñoz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.