包含 googleapis 后,云功能不会上传

Cloud function does not upload once googleapis are included

我有一个 google 云函数项目,一旦我包含 googleapis 以授权玩开发人员 api 我就无法再部署该项目。这是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);
}
})

我的 package.json 依赖部分中有这一行:"googleapis":"^94.0.0"

我使用这个命令部署 firebase --debug deploy --only functions:realtimeNotificationListener

调试输出不是很有帮助:

[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)

编辑/functions 文件夹中安装 googleapis 后,我得到了很多其他错误:

npm i googleapis --save 之后我得到:

npm audit fix 之后我得到:

firebase --debug deploy --only functions:realtimeNotificationListener 之后我得到:

我需要更改什么才能再次获得此 运行?

编辑 2

已修复 npm audit fix --forcenpm update

这个问题似乎是由于没有在正确的目录中安装依赖项造成的。

编写 Firebase 函数时,其所有依赖项都应安装在 /functions 目录中。

根据您的具体情况,"googleapis":"^94.0.0" 依赖项应添加到 /functions 目录中的 package.json,而不是主项目。要解决这个问题,我建议转到 /functions 目录和 运行 命令:

npm i googleapis --save

package-lock.json 应该在安装依赖项时自动更新,但如果没有,您可以创建一个新的,通过 运行 这个命令覆盖旧的:

npm i --package-lock-only

可以找到有关此命令的更多信息 here