Cannot parse environment for runtimeConfig
Hello everyone, i am currently build a nuxt webapp, i am trying to dockerize it but i am finding errors almost everywere i go, currently i have a "apiBaseUrl" in my runtimeConfig (not public) and have overridden it using "NUXT_API_BASE_URL" in my environment section in my Docker Compose file.
as i am seeing tho while running the app, it seems that it prints out as "undefined", i don't know why :( and don't know any way to debug this, any help is really appreciated, thanks!
18 Replies
Hi @NiceCraftz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Your issue is that the environment variable
Your setup is correct, but ensure the key is present in
NUXT_API_BASE_URL is not overriding your runtimeConfig.apiBaseUrl as expected in your Dockerized Nuxt app. Here’s what’s happening and how to fix it:
1. Environment Variable Naming and Mapping
Nuxt only overrides runtime config values with environment variables if the variable name matches the config key, uppercased, prefixed with NUXT_, and using underscores for camelCase boundaries. For your config:
The correct environment variable should be:
—which you are already using in your Docker Compose file.
2. Accessing the Value
When you access the runtime config in your app, use:
3. Debugging in Docker
Important: In production (when running the built app), Nuxt does NOT read from .env files. It only uses environment variables set in the environment (like in your Docker Compose environment: section) see docs.
4. Common Pitfalls
- Key must be defined in runtimeConfig: Only keys defined in runtimeConfig in your nuxt.config can be overridden.
- No process.env in runtimeConfig for runtime overrides: Setting apiBaseUrl: process.env.NUXT_API_BASE_URL only works at build time, not at runtime. You should set a default value (like an empty string or your local URL), and let Nuxt override it at runtime see docs.
- Check for typos: Make sure the key in runtimeConfig matches the environment variable name (case and underscores).
5. Example
nuxt.config.ts:
docker-compose.yaml:
Access in your app:
6. Additional Debugging
- Print all environment variables in your container to ensure NUXT_API_BASE_URL is set.
- Print useRuntimeConfig() in your app to see what’s available.
7. Reference
- Nuxt 3 Runtime Config: Environment Variables
- Nuxt 3 Runtime Config: Example
---
Summary:Your setup is correct, but ensure the key is present in
runtimeConfig and you are not using process.env for runtime overrides. Nuxt will automatically pick up NUXT_API_BASE_URL at runtime if set in the environment and the key is defined in runtimeConfig see docs. If it’s still undefined, double-check your Docker environment and that you’re not running in a way that ignores the environment variable.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@689519446578298982> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
no, as you can see i have set
runtimeConfig: {
apiBaseUrl: "http://localhost:8080",
},
and yes i am using the env NUXT_API_BASE_URL in my docker compose as i already sent
the problem is that when i call for example my pinia store
the apiBaseUrl is undefined.
also yes, i need to query my data from the server because i do not want to expose my api endpoints to the public.
seems like the get is passing and the other operations such as post aren't
vdsproduction | 2025-10-30T16:09:51.653+01:00 INFO 1 --- [vdsproduction] [nio-8080-exec-1] i.f.v.controller.ProductionController : Get all productions
vdsproduction | 2025-10-30T16:09:51.817+01:00 INFO 1 --- [vdsproduction] [nio-8080-exec-2] i.f.v.controller.ProductController : Getting all products
vdsviewer | [Vue Router warn]: No match found for location with path "/undefined/api/v1/product/"
also i have currently tried to remake my api access system to use this composable:
move your
useRuntimeConfig call outside of your functions get post and patch and have them at the top-level of useApiHelper
composables should not be called outside of the vue/nuxt contextGood video from Alex around composables
https://www.youtube.com/watch?v=N0QrFKBZuqA
Alexander Lichter
YouTube
Is your function REALLY a Vue composable?
💚 Vue's Composition API is amazing and my preferred way to write components nowadays. But often I see that developers don't know when functions are Vue composables, and when they are plain functions. Do you know?
In this video we will cover exactly this:
🧠 Explaining what a Vue composable actually is
✅ Going through a checklist to figur...
still doesn't work
still, its undefined in some cases
Listening on http://[::]:3000
API Base URL: http://localhost:8080
API Base URL: http://localhost:8080
[Vue Router warn]: No match found for location with path "/undefined/api/v1/product/"
[Vue Router warn]: No match found for location with path "/undefined/api/v1/product/"
API Base URL: http://localhost:8080
API Base URL: http://localhost:8080
get works, post and patch does not :=(
where you do you call useApiHelper ?
inside my pinia store
i am changing like big parts of my code related to store and data managment but i think i am just making a mess
could you provide me with the code
composables must be ran at the top in the nuxt context
which is in other composables, in script setup, etc
yes, let me git reset lol
here you go sorry.
this is a last change, i stil haven't tested this, but before i would call const {get} = useApiHelper() and then use it in a store function, so for every function i would have a useApiHelper call
which should not work because i am calling it out of the nuxt context
ok so you're calling your composable at the top level
which means when the module is imported that function immediately runs
which also means there's no guarantee it's called within the nuxt content
composables should be ran in other composables, or in vue setup
check this video for more info on how composables work
i did
generally speaking in nuxt you should never define a constant like that
cause there's always the chance of pollution
im not english sorry
but if i read stuff i understand better than talking
i never had this problem with nuxt honestly
i always deployed my apps without any problem, its the first time something like this happens
i can't get an idea on why it doesn't work and why that stupid apiBaseUrl variable is undefined, but when i run the get it works fine
like wtf
you shouldn't call your useApiHelper composable outside of the nuxt context
you're calling it at the module top level
you could try
to see if that helps
i'm not very familiar with pinia
no, it doesn't work
still is undefined.
as i said, fetch function with get method works, everything else doesn't
i don't know why i chose typescript honestly, could have done something better with my life
my assumptions now are that you call useProductionStore multiple times in multiple locations
if it only works for getting then the other ones must be called in an erroneous place
i fixed it with claude code in the end, that boy found it like in 3 seconds, and fixed it
idk how cuz he was so fast i will look after in the commit.