Search code examples
nuxt.jsextends

Nuxt 3 extending a project causes an error


Whenever I try to extend another Nuxt 3 project using:

export default defineNuxtConfig({   // this is inside the nuxt.config.ts in `main-project`
    extends: [
        '../test-extend'
    ]
})

I get an error saying that a module could not be found (for example: Cannot start nuxt: Cannot find module '@vueuse/nuxt')

My directory structure looks like this:

📂 
├── 📂 test-extend/
└── 📂 main-project/

Am I doing something wrong? I tried putting the test-extend project inside the main-project to see whether the path wasn't a problem but that didn't help either...


Solution

  • After some experimenting I found out that the error disappears when I add the dependencies of the parent layer (test-extend) to the main-project. This might seem like a super obvious solution in retrospect, however, I think it is a bug because the documentation mentions "Create Nuxt module presets" as one of the features of Nuxt Layers & I don't think this is really "creating a module preset" if I have to remember what dependencies are installed in the layer & then add them manually to the new project anyway.