According to Next.js documentation, you need to declare your env variables in next.config.js under env key to read them at build time:
env: {
GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID
},
This is working correctly in my local environment, the variables are hidden from _NEXT_DATA and I can still access them from the client. The problem is when deploying the application for production, it can no longer read from process.env. Has anyone encountered this issue?
Note: I don't want to expose sensitive data. Will adding the NEXT_PUBLIC_ prefix to the env variables expose them to _NEXT_DATA as well?