Precedence and Overrides
Your project always wins, then extends in the order you wrote it. The rule is three sentences long — the useful part is knowing which things override and which things merge.
What it is#
Nuxt flattens every layer into one ordered list, nuxt.options._layers. Position 0 is your own project. Then your extends entries, in the order you wrote them. Earlier means higher priority.
export default defineNuxtConfig({
extends: ["./layers/theme", "@acme/base"],
});
// _layers = [ your-project, ./layers/theme, @acme/base ]
// highest ─────────────────────────► lowest
Everything follows from that list:
- Same-named component or composable? Highest-priority layer wins, the rest are shadowed.
- Same route path? Highest-priority layer's page renders.
- Config values? Deep-merged, with higher priority overwriting scalars.
- Config arrays (
modules,css,plugins)? Concatenated, not replaced. - Hooks? All of them run. Layers don't shadow each other's hooks — they stack, lowest priority first.
Why you'd care#
Because "override one file from a layer" is the whole reason layers beat copy-paste, and because the array rule is the one that bites.
Overriding is what makes a base layer survivable. You inherit forty files and disagree with one. You don't fork the layer — you create the same path in your app:
@acme/base/app/components/SiteFooter.vue ← the layer's version
app/components/SiteFooter.vue ← yours. This one renders.
No config, no flag. Same name, higher layer, done.
Before#
The wrong instinct — copying the layer's whole component directory into your app "so I can change the footer", and inheriting a maintenance problem for one file.
After#
One file in your app shadows one file in the layer. The other thirty-nine keep updating when the layer updates.
If you need the original as a starting point, import it explicitly rather than re-implementing:
<script setup lang="ts">
// The layer's version is still on disk — reach for it by path when you only
// want to wrap it, not replace it.
import BaseFooter from "@acme/base/app/components/SiteFooter.vue";
</script>
<template>
<div class="border-t border-white/10">
<BaseFooter />
<p class="text-xs text-zinc-500">Extra line only this app needs.</p>
</div>
</template>
The array rule, concretely — this is where people expect override behaviour and get concatenation:
// @acme/base/nuxt.config.ts
export default defineNuxtConfig({
modules: ["@nuxt/image"],
css: ["@acme/base/assets/base.css"],
});
// your nuxt.config.ts
export default defineNuxtConfig({
extends: ["@acme/base"],
modules: ["@nuxt/content"],
css: ["~/assets/app.css"],
});
// result: modules = ['@nuxt/content', '@nuxt/image']
// css = ['~/assets/app.css', '@acme/base/assets/base.css']
You cannot remove a module a layer added by re-declaring modules. If a layer's module is optional, the layer should gate it behind its own config key — which is the layer author's job, not yours.
Do it yourself#
- In
layers/branding/app/components/, keepBrandBadge.vue. Createapp/components/BrandBadge.vuein the host app with different markup. Reload — yours renders. - Delete your copy. The layer's version comes back. That round trip is the entire override story.
- Add a second layer that also defines
BrandBadge.vue, and reorder theextendsarray. Watch which one wins follow the array order. - Print the resolved list and read it top to bottom:
hooks: {
'modules:done': (nuxt) => {
console.table(nuxt.options._layers.map((l, i) => ({
priority: i,
name: l.config?.$meta?.name ?? '(unnamed)',
cwd: l.cwd,
})))
},
}
Name every layer with $meta.name. An unnamed layer in that table is a layer you'll misidentify at 3am.
Gotchas#
- Overriding by filename, not by component name.
app/components/BrandBadge.vueshadows the layer'sapp/components/BrandBadge.vue. If the layer's file is atapp/components/brand/Badge.vue, the resolved name may match while the path doesn't — and which wins depends on registration priority, not on what you intended. Match the path. - Pages override by route, not by file path.
app/pages/learn/index.vueand a layer'sapp/pages/learn.vueboth claim/learn. Two files, one route, one loser. - Arrays concatenate.
modules,css,plugins,extendsitself. Expect additive behaviour and you'll never be surprised. - Hooks all fire. A layer's
build:beforedoesn't replace yours. If two layers both mutate the same config in a hook, order — lowest priority first — decides the final value. - Nitro server routes follow the same precedence, but a duplicate route is much harder to spot than a duplicate component. Namespace your layer's server routes under a prefix it owns.
Recap#
_layers[0] is you; extends follows in declaration order; earlier wins. Files override by path, config deep-merges, arrays concatenate, hooks stack. That's the complete mental model — the rest of this series is about doing real work inside it.
Next: Nuxt Layers: Going Further — promoting a folder to a workspace package, and the path bugs that come with it.