无法使用 Stripe 部署 firebase 云功能

Can't deploy firebase cloud functions with Stripe

我正在尝试使用 Firebase Cloud Functions 与 Stripe 通信API,但我无法部署任何功能,即使我只是在初始化 Stripe。

这是代码:

const fun = functions.region("europe-west2");
const secretKey = functions.config().stripe.key;
const pubKey = functions.config().stripe.push;
const stripe = new Stripe(pubKey, {
  apiVersion: "2020-08-27",
});

export const helloWorld = fun
    .https.onRequest((request, response) => {
      functions.logger.info("Hello logs!", {structuredData: true});
      response.send({
        "secret": secretKey,
        "pub": pubKey,
        "stripe": stripe,
      });
    });

我尝试在函数内部初始化 Stripe,但我得到了同样的错误。

错误:

firebase deploy --only functions:helloWorld

=== Deploying to '[PROJECT NAME]'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint --ext .js,.ts .

Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (90.78 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 14 function helloWorld(europe-west2)...
i  functions: cleaning up build files...
Function URL (helloWorld(europe-west2)): [URL HERE]

Functions deploy had errors with the following functions:
        helloWorld(europe-west2)

To try redeploying those functions, run:
    firebase deploy --only "functions:helloWorld"

To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

是否存在我没​​有发现的语法错误?我使用图书馆错了吗?我该怎么做才能解决这个问题?

原来我只需要 npm install stripe --save 在函数文件夹中,而不是在源文件夹中。