#Any way to Access Shell Env-Vars
29 messages · Page 1 of 1 (latest)
Are you using the useRuntimeConfig composable?
Yes
and i get only the initial value
we currently access our .env values as follows:
// nuxt.config
export default defineNuxtConfig({
runtimeConfig: {
public: {
cdn: process.env.CDN,
},
},
})
//index.vue
onMounted(() => {
const { public: $config } = useRuntimeConfig()
console.log($config.cdn)
})
Does it work without the Nuxt_ prefix?
yeah we don't have any NUXT_ prefixes in our env values
use the prefixes 🙂
NUXT_ and NUXT_PUBLIC_
🤯 Throughout my projects, consultancies and code reviews I came across lots of interesting findings - also with regards to Nuxt's runtimeConfig feature. Repeatedly I noticed ONE big mistake though which you might do at this very moment in your project. In this video, explain what it is, why you shouldn't do it and how to use runtimeConfig correc...
Thank you, is there a way to use vars without the prefix something like NUXT_PUBLIC_VAR=$OTHER_VAR?
Because i need my commit hash and my deployment service exposes this in an custmo var
it depends on when/where you need it in the process, but you could copy it to a variable with the prefix like your example
NUXT_PUBLIC_VAR=$OTHER_VAR node .output/server/index.mjs etc
or before your build command
I need it at least on the client side. Because i want to set in the HTML Tag a build-id with the Commit Hash. I tried that:
But it dont work
I have following code in app.vue-script-setup: console.log('commit-id: ', config.public.commitId) to test it but it dont show the env value
what platform is this?
This was coolify. But i try it now with vercel if the problem persists
In vercel it also dont work
does it set "TEST" when you NUXT_PUBLIC_COMMIT=TEST
Yes, this works
So my problem is only how i can set a env var based on another env var
are you sure the original variable exists?
try this:
NUXT_PUBLIC_VAR=$OTHER_VAR; node .output/server/index.mjs
or NUXT_PUBLIC_VAR=$OTHER_VAR && node .output/server/index.mjs
Unfortunately both options don't work