Next.js Discord

Discord Forum

.env var not defined on deploy

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
1. I have GOOGLE_MAPS_API_KEY. I put it inside .env file.
2. In map component I use this {googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY} and locally it works.
3. Map component is client side rendering, so i added in next.config.js file this code env: { GOOGLE_MAPS_API_KEY: process.env.GOOGLE_MAPS_API_KEY }
4. But after deploy i don't see map, because api key not defined.

What could be causing the problem and how to solve it? how to hide secret on deploy?
Answered by Pond loach
Try to set them in your project / settings / environment variables
then we'll see if it works
View full answer

8 Replies

Pond loach
Hi, are you deploying on Vercel ?
@Pond loach Hi, are you deploying on Vercel ?
Cape lionOP
Hi, i deploy through Vercel
Pond loach
Did you set the environement variables on Vercel ?
Pond loach
Try to set them in your project / settings / environment variables
then we'll see if it works
Answer
@Pond loach Try to set them in your project / settings / environment variables then we'll see if it works
Cape lionOP
It works. After add api_key definitely needs to be redeployed. Thanks a lot!
Pond loach
My pleasure 🚀