#Greetings400 - env Issue

1 messages · Page 1 of 1 (latest)

tepid echo
#

Hello! Can you provide more information? You said it can't be read... do you get an error? Does it silently fail? Something else?

gray hull
#

Hi! I will check for the error message. But it wasn't possible to proceed to checkout.

#

The error message is:

Uncaught (in promise) IntegrationError: Missing value for Stripe(): apiKey should be a string.
at V (v3:1:10864)
at J (v3:1:10934)
at new e (v3:1:245823)
at Yc (v3:1:276529)
at initStripe (webpack-internal:///./node_modules/@stripe/stripe-js/dist/stripe.esm.js:105:28)
at eval (webpack-internal:///./node_modules/@stripe/stripe-js/dist/stripe.esm.js:129:12)

blazing solstice
#

Shot in the dark because I haven't actually tried that tutorial, but did you add your publishable key to your .env file after starting your server, @gray hull?

#

You may need to restart

gray hull
#

Only running it locally with "npm run dev".

blazing solstice
#

Yeah, stop and then restart your server.

gray hull
#

Tried stopping and starting again. but the same error shows.

tepid echo
#

If you log process.env is the output what you would expect?

gray hull
#

I will try.

#

This logged. It's what you meant?

import { loadStripe } from '@stripe/stripe-js';

let stripePromise = null;

const getStripe = () => {
if (!stripePromise) {
console.log('pk_test_51K4...');
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);
}
return stripePromise;
};

export default getStripe;

#

It logged in the web browser.

tepid echo
#

No, like this: console.log(process.env); and then see if that's working/being populated as expected.

gray hull
#

Ah ok! Will try it.

#

console.log(process.env) logges: {} get-stripe.js?b0a2:7
console.log(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY) logges: undefined get-stripe.js?b0a2:7

tepid echo
#

That indicates process.env is an empty object.

blazing solstice
#

Where in your project is the .env file located? Are you using src/?

gray hull
#

It's located in the .env.local file on the same level as "pages". Not using src/.

blazing solstice
#

I just downloaded the project and tried adding my publishable key to try and reproduce. Here's my publishable key

#

My project setup is the same:

gray hull
#

And it works fine?

#

Mine looks similar. Added spaces between.

NEXT_PUBLIC_PUBLISHABLE_KEY=pk_test_...

STRIPE_SECRET_KEY=sk_test_...

STRIPE_WEBHOOK_SECRET=whsec_...

blazing solstice
#

Yeah, it's working fine. I'm logging it here in the console:

#

I can render it just fine:

#

I think it might be a spelling error?

#

Your .env file has NEXT_PUBLIC_PUBLISHABLE_KEY but your code snippet was NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY

gray hull
#

Oh wow! There you got it!!!

#

Thanks for walking the extra mile!! 🙂

blazing solstice
#

Happy to help, @gray hull!

gray hull
#

Your awesome!