How do you actually use ENV variables? #1397
Replies: 2 comments 8 replies
-
Is the proper approach to just get the ENV variables in the renderer and then pass them down to the pageContext so they can be used in a client component? As these are Public ENVs and not "secret", this seems secure and the only way to do it, as far as I can tell. Otherwise, the Importmeta doesn't seem to work in children components, apparently you can only use it in the Page? |
Beta Was this translation helpful? Give feedback.
-
Have you seen this note?
|
Beta Was this translation helpful? Give feedback.
-
Simple issue, but driving us nuts. How do you use ENV variables on client code and server code?
We read the docs here: https://vike.dev/env
We created a .env.development file and added an ENV variable.: PUBLIC_ENV__SOME_KEY=123
We then called this variable in a function: {import.meta.env.PUBLIC_ENV__SOME_KEY} (in react) or in backend function: const testKey = import.meta.env.PUBLIC_ENV__SOME_KEY
But this ENV is undefined? Actually, the editor gives the error:
Property 'env' does not exist on type 'ImportMeta'.
So totally confused by how to do this in a React application. In NextJS, we just used process.env in the react code to get the public variables, NEXT_PUBLIC.
And actually, we are trying to implement a link component, like you show here: examples/base-url-server/components/Link.jsx - but that example uses the import.meta. how??
Beta Was this translation helpful? Give feedback.
All reactions