Can't deploy firebase cloud functions with Stripe

Viewed 236

I'm trying to use Firebase Cloud Functions to communicate with Stripe API, and I am unable to deploy any functions, even if I'm only initializing Stripe.

This is the code:

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,
      });
    });

I tried initializing Stripe inside the functions, but I get the same error.

Error:

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.

Is there a syntax error I'm not seeing? Am I using the library wrong? What can I do to fix this?

1 Answers

Turns out I just needed to npm install stripe --save inside the functions folder, and not in the source folder.

Related