N
Nuxt5d ago
NelRen

imports into layers folders give me errors ( Cannot find module ) but not always, I am using Nuxt 4

is it common ? And how to solve it ?
3 Replies
kapa.ai
kapa.ai5d ago
Hi @NelRen. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Nuxt 4 has had several known issues around layers, imports and TypeScript, so what you’re seeing is not unusual. From the shared sources, there are a few relevant points: 1. Layer priority & resolution bugs (fixed)
There was a bug where component resolution didn’t correctly respect layer order; this could make imports/components from some layers appear “missing” or resolve unpredictably. This was fixed by basing priority on the layer index instead of a simple root/non-root flag.[layer priority] 2. Layer app/ and server/ not included in TS configs (fixed)
- layers/*/app/** was not properly included in the generated TS configs, causing IDE / TS tooling to report “Cannot find module” or missing types even though the app runs.[layer app tsconfig]
- Similarly, layers/*/server/** was missing from .nuxt/tsconfig.server.json, leading to errors like “Cannot find name 'defineNitroPlugin'” in server files inside layers.[layer server tsconfig]
These were fixed so that layer app/ and server/ folders are now automatically included in the generated TS configs, improving type resolution in editors and removing many “Cannot find module” / “Cannot find name …” errors. 3. Alias and Nitro-related path resolution fixes
- Nitro/layer public folders and Nuxt aliases were not correctly resolved before, which affected things like publicAssets and public in layers; this has been fixed so Nuxt aliases now work there.[nitro config layers]
- Several fixes were made around using reverseResolveAlias and resolving paths (including aliases) before appending subpaths, to avoid incorrect resolution and improve error messages.[reverseResolveAlias; resolve module paths] What this means for you - Yes, it’s been a common pain point, especially in early Nuxt 4.x versions: imports inside layer app/ or server/ directories and alias-based paths could give “Cannot find module” or missing-types errors in TS/IDE, even when the app runs. - Upgrading Nuxt to a version that includes these fixes (newer than the PRs above) is the main recommended solution, as they change how TS configs and aliases for layers are generated. Practical steps 1. Make sure you’re on a Nuxt 4 version that includes: - Layer TS config fixes for app/ and server/[layer app tsconfig; layer server tsconfig] - Alias and path resolution fixes[reverseResolveAlias; resolve module paths] 2. After upgrading: - Delete .nuxt/ and node_modules/, then reinstall and run nuxi dev / nuxi build to regenerate TS configs. - Verify that .nuxt/tsconfig.json and .nuxt/tsconfig.server.json now include your layers/*/app/** and layers/*/server/** paths. If you still see “Cannot find module” after upgrading and regenerating, the provided sources don’t give more specific remedies beyond these fixes, so the next step would be to check your exact Nuxt version and layer structure or share a minimal repro. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5d ago
<@250643144863907841> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
NelRen
NelRenOP5d ago
i do not use layers/app folders, I use /layers directory at the project root level and inside I have ( e.g : layers/layername1/composables , pages, stores, etc ..... )

Did you find this page helpful?