Override layer via c12 environment
Hi everyone,
after looking through c12 issues for a bit im still usure whether this is actually possible.
For local development I want to use the layer from a relative path. However when other people use it, i wouldn't want them to have to set up all repositories.
My config looks like something like this:
However it seems that it always defaults to the remote source, no matter the envName.
Does anyone know why that could be?
Thanks a lot đ
5 Replies
Hi @Tom. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Your approach to overriding the
- Your config is syntactically correct for environment overrides. - The knowledge sources do not explicitly confirm that
extends property in nuxt.config using c12's environment-specific configuration is correct in principle. According to the Nuxt documentation, you can use $env and environment overrides in your nuxt.config.ts to provide different configurations for different environments, and this includes the extends property. You should be able to run Nuxt with a specific environment using the --envName flag, for example: nuxt dev --envName local Nuxt 4.x Configuration.
However, the knowledge sources do not explicitly confirm that the extends property itself is always correctly overridden by environment-specific configuration. The documentation shows examples of overriding other config options (like routeRules), but does not provide a direct example of overriding extends in this way. There may be limitations or issues in how Nuxt or c12 merges the extends property, especially since extends is a special property that affects how layers are loaded at startup.
If you find that the override is not working and it always defaults to the remote source, this could be due to how Nuxt or c12 processes the extends property before applying environment overrides. The documentation suggests that for more details on the mechanism, you should refer to the c12 documentation on environment-specific configuration, but the Nuxt docs do not guarantee that all properties (especially those affecting project structure like extends) are always overridden as expected Nuxt 4.x Configuration.
Summary:- Your config is syntactically correct for environment overrides. - The knowledge sources do not explicitly confirm that
extends can be reliably overridden via $env in all cases.
- If it always defaults to the remote source, this may be a limitation or bug in Nuxt or c12.
- For now, you may need to use a manual approach (e.g., separate config files or scripts) if this override is critical for your workflow.
If you need a definitive answer or a workaround, you may want to open an issue on the Nuxt or c12 GitHub repositories, as the documentation does not provide enough detail to confirm or deny this behavior.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@248144945632903168> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai I could probably solve this temporarily using
process.env.xxx = local ? '..base' : 'github:refilelabs/base' right? That doesnt feel as clean thoughLet me check the knowledge base for you again. One moment! :books:
----------------------
You are correct that you could use an environment variable to conditionally set the layer source, for example:
However, the official Nuxt documentation advises against setting
runtimeConfig values from differently named environment variables (e.g., mapping to process.env.OTHER_VARIABLE), as this only works at build-time and will break at runtime. While this warning is specifically about runtimeConfig, it highlights that relying on process.env for config branching can have caveats, especially in production builds Nuxt 4.x Runtime Config.
For the extends property, the documentation does not explicitly state whether this pattern is officially supported or recommended. There is also no explicit example of using process.env directly in the extends array for layers. So, while your approach may work as a temporary solution for local development, it is not documented as a best practice and may have limitations or unexpected behavior, especially in more complex setups or when building for production.
If you need a more robust or officially supported solution, you may want to follow up with the Nuxt or c12 maintainers, as the knowledge sources do not provide a definitive answer for this use case.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@248144945632903168> Kapa.ai is still learning and improving, please let me know how I did by reacting below.