How do I get Amplify's Environment Variable on a Vite React application? I've tried console logging to the import.meta.env, but only the process_env is showing. What do I need to do?
Asked
Active
Viewed 133 times
1
-
Can you share the environment variable names here? – Allan Chua Jun 30 '23 at 07:27
-
1Hi Sir @AllanChua, we've found out the reason why. We apparently had to rebuild the app in order for the env variable to show. – Kim Joseph Penaloza Jun 30 '23 at 07:35
-
1OK cool! I've just placed a common problem with `VITE_` environment variables just in case somebody would need it moving forward. – Allan Chua Jun 30 '23 at 07:36
2 Answers
1
The reason why it wasn't showing was that we added the environment variable AFTER the build. In order for the environment variable to show, you have to declare it first before building.

Kim Joseph Penaloza
- 59
- 7
0
Please rename your environment variables so that they'd start with VITE_
prefix. According to the Vite documentation, any environment variable that does not start with VITE_
will not be exposed on the browser side for the purpose of preventing accidental leaking of variables.

Allan Chua
- 9,305
- 9
- 41
- 61
-
Yes sir, as per the documentation, we need to add the VITE_ prefix on the environment. The problem was that the environment variables were added after the build. – Kim Joseph Penaloza Jun 30 '23 at 07:37