#Greetings400 - env Issue
1 messages · Page 1 of 1 (latest)
Hello! Can you provide more information? You said it can't be read... do you get an error? Does it silently fail? Something else?
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)
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
Only running it locally with "npm run dev".
Yeah, stop and then restart your server.
Tried stopping and starting again. but the same error shows.
If you log process.env is the output what you would expect?
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.
No, like this: console.log(process.env); and then see if that's working/being populated as expected.
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
That indicates process.env is an empty object.
Where in your project is the .env file located? Are you using src/?
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:
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_...
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
Happy to help, @gray hull!
Your awesome!