0

I want to use a variable from the .env file, but I'm getting the following error:

Uncaught (in promise) IntegrationError: Please call Stripe() with your publishable key. You used an empty string.

code

import Stripe from "stripe";

const stripe = new Stripe(process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY);

.env

NEXT_PUBLIC_STRIPE_SECRET_KEY=***
0

1 Answer 1

2

In Next.js you should declare your environment variables in a .env.local file.
For more informations check the official docs.

However, as suggested by @juliomalves, you can declare your environment variables in a .env.* file, making sure that you respect the environment variables load order.

Sign up to request clarification or add additional context in comments.

1 Comment

Using .env is also fine, as long as you don't have any other more specific .env.* file present (which may be why OP was experiencing the issue). See nextjs.org/docs/basic-features/….

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.