#Any way to Access Shell Env-Vars

29 messages · Page 1 of 1 (latest)

cyan wind
#

When i try to set a env var at runtime it doesnt work.
I have following in public runtime config in nuxt.config: test: process.env.NUXT_TEST and i set the var for NUXT_TEST in service like vercel and let console.log it it says the var is null.

median vector
#

Are you using the useRuntimeConfig composable?

cyan wind
#

Yes

cyan wind
#

and i get only the initial value

stiff monolith
#

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)
})
cyan wind
#

Does it work without the Nuxt_ prefix?

stiff monolith
#

yeah we don't have any NUXT_ prefixes in our env values

quartz gazelle
#

use the prefixes 🙂

#

NUXT_ and NUXT_PUBLIC_

cyan wind
#

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

quartz gazelle
#

NUXT_PUBLIC_VAR=$OTHER_VAR node .output/server/index.mjs etc

#

or before your build command

cyan wind
#

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

quartz gazelle
#

what platform is this?

cyan wind
#

This was coolify. But i try it now with vercel if the problem persists

cyan wind
#

In vercel it also dont work

quartz gazelle
#

does it set "TEST" when you NUXT_PUBLIC_COMMIT=TEST

cyan wind
#

Yes, this works

#

So my problem is only how i can set a env var based on another env var

quartz gazelle
#

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

cyan wind
#

Unfortunately both options don't work

quartz gazelle
#

ok can you try NUXT_PUBLIC_VAR=$VERCEL_GIT_COMMIT_SHA && node .output/server/index.mjs

#

(if you are using vercel)