N
Nuxt6d ago
Tirtho

nuxt 4 import from main app to layer

I have a store in my app, I want to import it into my layer, is this possible or an antipattern
2 Replies
kapa.ai
kapa.ai6d ago
Hi @Tirtho. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Nuxt’s layer model, code is meant to flow from layers into the app, not the other way around. A layer is effectively a base/template that an app extends, so importing from the main app back into a layer creates a circular dependency and is considered a bad pattern. Nuxt is even adding special aliasing and TypeScript support that assumes this directionality (layers as dependencies of the app, not dependents of it). For example, layers get their own aliases like #layers/example-layer and dedicated app/ / server/ handling inside the layer itself, reinforcing that they are standalone, reusable units that an app consumes.[named layer aliases; layer app/server tsconfig] So: - Importing a store from a layer into the main app is normal. - Importing a store from the main app into a layer is not supported by the design and is effectively an antipattern. If you need that store logic in both, move it into the layer (or a shared package) and let the app consume it from there. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6d ago
<@1430812111118012417> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?