DEV Community

v0id-4lps
v0id-4lps

Posted on • Updated on

Nuxt3 : limitation on Layers & Modules

Nuxt is a good framework.

I've been using it for a few months now and it's good, but I found some limitations that were annoying for a professional use.

Layers & modules

Nuxt's Layers and modules allows you to split your code as reusable parts.

  • a layer for your shared UI components
  • a layer for your auth system
  • ...

But each layer can requires specific packages for it's business.

Limitation

If your layers/modules requires dependencies to work, Nuxt will not install these dependencies on npm install or npm build on your projects and you won't be able to run em.

Documentation is very poor and unclear about theses two features.

Workaround

I tested a lot of tricks, asked the community but there is no workaround for now except manually install your layers'/modules' dependencies into each one of your projects.

It's very limitative and annoying if you want to use your layers/modules on several projects and this make it loses all the interest of these features: easy reusability.

In my opinion, layers and modules are most of time useless in this state.

Keep this in mind before starting a big and professional project with it. 😣

Top comments (2)

Collapse
 
avxkim profile image
Alexander Kim

Hey, i wonder if adding these dependencies in a package.json's peerDependencies would work? You'll just have to use pnpm i after extending some layer. What do you think?

Collapse
 
v0id-4lps profile image
v0id-4lps • Edited

Hey!
I tested it and it's not working.

I use the feature to extend layer from a distant GIT repo.

export default defineNuxtConfig({
    extends: [["github:myAccount/myLayerRepo", { install: true, auth: process.env.GITHUB_TOKEN }]],
Enter fullscreen mode Exit fullscreen mode

In this case the layer is not installed as an npm package but cloned from repo by unjs/giget in /myProject/node_modules/.c12/github_myLayerRepo_xxx and it's dependencies are not installed.

Thank you for the tip anyway :)

It's not practical nor what I want but I'll publish my layer as an npm package. It should work considering the Nuxt3 documentation.