I have a next.js app with Stripe Elements running on AWS Amplify. Everything works great locally but on live i get an error An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
which in the logs relates to “Invalid API Key provided”
I’ve tracked the issue down to this file
import "server-only";
import Stripe from "stripe";
const dotenv = require("dotenv");
dotenv.config();
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
apiVersion: "2024-04-10",
});
The STRIPE_SECRET_KEY
isn’t loading on live, I’ve added the ENV var but it doesn’t seem to be picked up via process.env.STRIPE_SECRET_KEY
if I hard code the key it works fine.