try to console log the environment variable and see if it is coming right after building the app or not. BTW this should not be an issue if the application is running smoothly in development. Also if you are going to deploy the frontend to a platform like vercel you need to set environment variables separately.