1

I try to deploy some cloud functions in typescript for a firebase project:

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import Stripe from "stripe";

admin.initializeApp();
const stripe = new Stripe(functions.config().stripe.secret, { apiVersion: "2025-02-24.acacia" });

// Cloud Function to Create a Stripe Checkout Session
export const createCheckoutSession = functions.https.onCall(async (data, context) => {
    if (!context.auth) {
        throw new functions.https.HttpsError("unauthenticated", "User must be authenticated");
    }

    const { priceId, userId } = data;
    if (!priceId || !userId) {
        throw new functions.https.HttpsError("invalid-argument", "Missing required parameters");
    }

    try {
        const session = await stripe.checkout.sessions.create({
            payment_method_types: ["card"],
            mode: "subscription",
            customer_email: context.auth.token.email,
            line_items: [{ price: priceId, quantity: 1 }],
            success_url: "https://your-app.com/success",
            cancel_url: "https://your-app.com/cancel",
        });

        return { sessionId: session.id };
    } catch (error) {
        throw new functions.https.HttpsError("internal", "Stripe session creation failed", error);
    }
});

// Cloud Function to Handle Stripe Webhooks
export const handleStripeWebhook = functions.https.onRequest(async (req, res): Promise<void> => {
    const sig = req.headers["stripe-signature"] as string;
    const endpointSecret = "your_stripe_webhook_secret";

    let event: Stripe.Event;
    try {
        event = stripe.webhooks.constructEvent(req.rawBody, sig, endpointSecret);
    } catch (err) {
        res.status(400).send(`Webhook Error: ${(err as Error).message}`);
        return;
    }

    if (event.type === "checkout.session.completed") {
        const session = event.data.object as Stripe.Checkout.Session;
        await admin.firestore().collection("subscriptions").doc(session.customer_email!).set({
            userId: session.customer_email,
            subscriptionId: session.subscription,
            status: "active",
            createdAt: admin.firestore.FieldValue.serverTimestamp(),
        });
    }

    res.status(200).send("Success");
});

but I get:

✔ functions: functions folder uploaded successfully i functions: creating Node.js 18 (1st Gen) function createCheckoutSession(us-central1)... i functions: creating Node.js 18 (1st Gen) function handleStripeWebhook(us-central1)...

Functions deploy had errors with the following functions: createCheckoutSession(us-central1) handleStripeWebhook(us-central1) Error: There was an error deploying functions:

  • TypeError Cannot read properties of null (reading 'length')
  • TypeError Cannot read properties of null (reading 'length')

I get the same if I try with empty functions, which is confusing:

import * as functions from "firebase-functions";

// Cloud Function to Create a Stripe Checkout Session
export const createCheckoutSession = functions.https.onCall(async (data, context) => {

});

// Cloud Function to Handle Stripe Webhooks
export const handleStripeWebhook = functions.https.onRequest(async (req, res): Promise<void> => {

});

Could it be a configuration problem?

Edit: the issue linked in order to close this question does not solve the problem.

5
  • As covered in the linked thread, change from "firebase-functions"; to from "firebase-functions/v1"; Commented Mar 28 at 13:27
  • Additionally, functions.config() is deprecated, use defineString("NAME") instead. Commented Mar 28 at 13:30
  • @samthecodingman it doesn't work for me, still have the same errors Commented Mar 28 at 13:55
  • I'm wondering if you're hit by this: stackoverflow.com/questions/79542406/… (I can't find a link to the bug mentioned in the answer there yet) Commented Mar 28 at 21:54
  • @FrankvanPuffelen Yes it was that. That issue should be the one linked Commented Mar 29 at 20:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.