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.
from "firebase-functions";tofrom "firebase-functions/v1";functions.config()is deprecated, usedefineString("NAME")instead.