NEXT_PUBLIC_ prefix key is not readed in client side
See original GitHub issueWhat version of Next.js are you using?
11.0.1
What version of Node.js are you using?
12.16.2
What browser are you using?
Chrome
What operating system are you using?
Ubuntu Mate
How are you deploying your application?
Google cloud Run - Secrets
Describe the Bug
I am using this example to use google analytics in my project. My variable is NEXT_PUBLIC_GA_ID
When I use .env.local in local client side is reading the enviroment variable successfully.
But when I deploy on google cloud run the environment variable is not readed in client side (undefined
). In google cloud I use google secrets to give access to some env-vars in this container (I am not using .env.local there).
I checked Google Secrets configuration in cloud run with a print in server logs
Also I am return this variable in /api/hello endpoint and I read correctly (Obvioslly is server side returning)
To summary: I have access to this env var in server side but not in client side even though I am using prefix
NEXT_PUBLIC_
Expected Behavior
To Reproduce
I used exactly this code https://github.com/vercel/next.js/tree/canary/examples/with-google-analytics
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Client-side variables are inlined, meaning they will be replaced with their actual value build time! Setting it runtime doesn’t have an effect in the client bundle. Make sure the env variable is present when you build your app.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.