#Nuxt Layers + Modules Dependency issue
1 messages · Page 1 of 1 (latest)
Nuxt’s docs don’t explicitly describe your exact @nuxt/ui + remote GitHub layer scenario, so I can’t say with certainty how nuxt prepare is resolving that dependency. But there are a few relevant points about layers and dependencies:
-
Remote layers’ dependencies live in their own node_modules
When you extend a remote Git repo as a layer, Nuxt usesc12/gigetand installs that layer (and its dependencies) into a special location under your project’snode_modules/.c12/.... Those dependencies are not automatically available to your main app’s package manager. [Publishing layers] -
Docs recommendation for npm‑published layers
When publishing a layer as an npm package, Nuxt recommends putting anything the layer imports into that package’sdependencies, and then installing that package in the consuming project. [Publishing layers]
That pattern assumes the consuming project has the layer package installed as a dependency/devDependency, so its dependencies are resolvable during Nuxt’s lifecycle. -
Module loading order vs. resolution
Nuxt guarantees that layer modules run before project modules, and project modules have higher priority. [Corrected module loading order]
But this is about execution order, not about how Node resolves@nuxt/uiwhennuxt prepareruns.
Given this, the safest and most “Nuxt‑aligned” pattern today is:
- The layer’s
package.jsonshould list@nuxt/uiin itsdependencies. - The consuming app should install the layer itself as a dependency (npm package or git dependency). [Publishing layers]
For remote Git layers specifically, the docs also warn that dependencies of the remote layer are not generally usable “outside of Nuxt” because they live under .c12. [Publishing layers] That suggests that if Nuxt’s own tooling (like nuxt prepare during npm install) cannot resolve @nuxt/ui from that special location, you may indeed need to:
- Also install
@nuxt/uiin the main app so thatnuxt preparecan resolve it from the project’snode_modules.
So, to your concrete questions, based only on the docs:
- The docs do not clearly state that “having the dependency only in the base layer is sufficient” for remote Git layers.
- The docs do imply that for reusable layers, the recommended pattern is to publish them as npm packages and install that package (with its dependencies) in the consuming app. [Publishing layers]
Given your error only appears during npm install / nuxt prepare, the most reliable fix consistent with the docs is:
- Either publish/use the base layer as an npm package and install it in
main-app, or - Keep using the Git layer but also add
@nuxt/uias a dependency inmain-appso Nuxt can resolve it during prepare.
If you want to avoid duplicating dependencies, the npm‑package approach for the base layer is the pattern Nuxt documents explicitly.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@dim knot Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@orchid oasis I did some changes to my Nuxt layers app (base-app). creating a new component and updating styles. but when trying to use it via extends: [
['gh:Autoo-ma/autoo-base-app#main', { auth: process.env.GIGITHUB_TOKEN, install: true }]
],
I can't access to the new component (Failed to resolve component)
Let me check the knowledge base for you again. One moment! :books:
The knowledge sources don't contain specific information about component resolution failures with remote GitHub layers, so I can only share what the docs do say that's relevant to your situation.
Most likely cause: cached layer from a previous clone
When you use github: (or gh:) as a layer source, Nuxt uses giget to clone the repo into a local cache (under node_modules/.c12/). If the cache isn't invalidated, your new component won't be picked up even after you push changes to main.
What to try:
-
Delete the cached layer — remove the cached clone so Nuxt re-fetches it:
rm -rf node_modules/.c12Then re-run
npm install/nuxt prepare. -
Pin to a specific tag or commit instead of
#main, so you can be sure you're pulling the exact version you expect:export default defineNuxtConfig({ extends: [ ['github:Autoo-ma/autoo-base-app#v1.0.1', { auth: process.env.GIGITHUB_TOKEN, install: true }] ] }) -
Verify the component is in the correct directory — in Nuxt 4, layer components must be under
app/components/*(not justcomponents/*) to be auto-scanned. [Authoring Nuxt Layers] -
Avoid
~/aliases inside the layer — if your new component imports assets or other files using~/, those aliases resolve relative to the consuming project, not the layer, which can cause resolution failures. Use relative paths inside the layer instead. [Relative Paths and Aliases]
Beyond these points, the knowledge sources don't provide more detail on remote layer caching behavior, so I'd recommend also checking the Nuxt GitHub issues for similar reports.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@dim knot Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@orchid oasis I have removed the .c12 and reinstall the packages. but still it's not get the latest commit from github repo
Let me check the knowledge base for you again. One moment! :books:
The knowledge sources don't contain specific information about how Nuxt/giget handles cache invalidation or forces a fresh fetch from a remote GitHub layer source, so I can't give you a fully evidence-based answer on the internals of that caching mechanism.
What the docs do say is relevant here:
- Nuxt uses unjs/giget to fetch remote git sources. [Going Deeper] The caching and fetching behavior is ultimately controlled by
giget, not Nuxt itself — so for detailed cache behavior, thegigetandc12documentation would be the authoritative source.
Practical suggestions based on what the docs support:
-
Pin to a specific commit SHA or tag instead of
#main. Using a branch name like#mainmay causegigetto serve a cached version. Pinning to a specific tag or commit hash forces it to fetch a distinct version:export default defineNuxtConfig({ extends: [ ['github:Autoo-ma/autoo-base-app#v1.0.2', { auth: process.env.GIGITHUB_TOKEN, install: true }] ] }) -
Consider publishing the base layer as an npm package instead of using a raw GitHub source. The docs explicitly recommend this pattern for reusable layers, and it gives you proper versioning and reliable dependency resolution. [Publishing layers]