New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic runtime public environment variables using publicRuntimeConfig are undefined #9195
Comments
@Sletheren Could you provide a reproduction? 🙏 Here is an example of Nuxt correctly reading an environment variable at runtime that does not exist in |
Hi @danielroe , here is a reproduction of the issue: https://github.com/Sletheren/nuxt-typescript-envs |
@Sletheren Thanks. The issue is that you aren't copying your |
Seems like copying |
@Sletheren Great - glad that's working! In terms of accessing (If you still think something's off, just ping me and I'll reopen the issue.) |
Hi @danielroe , thanks for the time and thorough explanation! |
@danielroe also, I have some settings on my |
I have similar problem with publicRuntimeConfig. It always return undefined although I followed exactly the documentation. env: { |
@bangrobe You can't access apollo: {
clientConfigs: {
default: {
httpEndpoint: process.env.GRAPHQL_HTTP
}
}
} |
@danielroe When I use this.$config in my app, It will show undefined if I don't hardcoded the url in publicRuntimeConfig. TypeError: [Apollo module] Client configuration "default" must define httpEndpoint or link option.` |
@bangrobe You might find this blog article helpful in terms of using runtimeConfig. For |
@danielroe Yes, I tried both of them today. Took me 5 hours to test all possible combinations. And there are many type of errors happened. Example with graphql declare sometimes I will get ""TypeError: Cannot read property 'resolved' of undefined"." |
I'm having this very same issue reported at the beginning. I have a k8s pod which mounts a |
same issue here: nuxt.config.js: app.vue: ${this.$config.baseUrl} return undefined any help? |
@StefanoTesla If you could creata new issue with a reproduction, I'll have a look 🙂 |
@StefanoTesla Looks like a typo? |
Have any chance to disable this option to nuxt change process.env.* to "hardcoded" value? for any runtime get new value? |
Same issue. My problem was that i changed everything in my nuxt app to use es module instead of commonjs require. So i used a workaround : Instead of exporting to default the nuxt config i exported a function that uses process.env as parameter : export default function getNuxtConfig (envVariables) {
return {
//Nuxt config
publicRuntimeConfig: {
HOST: envVariables.HOST,
PROTOCOL: envVariables.PROTOCOL,
PORT: envVariables.PORT,
etc...
},
}
} And then in server/index.js : import getNuxtConfig from '../nuxt.config.js'
// Import and Set Nuxt.js options
const config = getNuxtConfig(process.env)
const nuxt = new Nuxt(config) Hope it helps |
I got it working by deleting the dist folder or the In my
and testing in
|
There's some trick to try: nuxt-modules/apollo#258 (comment) |
All env variables in Nuxt.js must start with NUXT_ENV. |
The issue:
I am trying to achieve this requirement:
BasePath
)API_URL
I am building my application for production
nuxt build --production=true
and running it on a docker container where I pass some environment variablese.g API_URL, ...etc
My
nuxt.config.js
has the definition of those env variables:I run my docker with the built-image:
And I access those variables using the
$config
property in Vue:What is Expected?
The expected behaviour is whenever I run
my_image_name
with different by passing different env variables, I can see those values.What is actually happening?
All the
publicRuntimeConfig
areundefined
on run time!Note:
Running it locally works fine, because the env variables are read from
.env
file, which doesn't exist on production, but rather the env variables...Versions
The text was updated successfully, but these errors were encountered: