Skip to content

Manually Typed RuntimeConfig inside Layer causes TypeScript error in app using this layer. #22282

@DawidKopys

Description

@DawidKopys

Environment

App:

- Operating System: `Darwin`
- Node Version:     `v18.16.0`
- Nuxt Version:     `3.6.5`
- Nitro Version:    `2.5.2`
- Package Manager:  `npm@9.5.1`
- Builder:          `vite`
- User Config:      `extends`, `typescript`, `devtools`
- Runtime Modules:  `-`
- Build Modules:    `-`

Layer:

- Operating System: `Darwin`
- Node Version:     `v18.16.0`
- Nuxt Version:     `3.6.5`
- Nitro Version:    `2.5.2`
- Package Manager:  `npm@9.5.1`
- Builder:          `vite`
- User Config:      `typescript`
- Runtime Modules:  `-`
- Build Modules:    `-`

Reproduction

  1. clone repo https://github.com/DawidKopys/nuxt-layers
  2. Run npm i in nuxt-layer directory
  3. Run npm i in app directory
  4. Run npx vue-tsc --noEmit / npm run dev / npx nuxi typecheck inside app directory. You should get below error:
../nuxt-layer/modules/testModule.ts:13:16 - error TS2664: Invalid module name in augmentation, module 'nuxt/schema' cannot be found.

13 declare module 'nuxt/schema' {
                  ~~~~~~~~~~~~~


Found 1 error in ../nuxt-layer/modules/testModule.ts:13

Describe the bug

I am defining a module inside a layer. This module exposes its options to runtime (as per nuxt docs).

I want to type these runtime options manually so that I can have better DX inside other parts of the layer. For example - I would like to have both working typecheck and IntelliSense for the testModuleRuntimeConfig inside /nuxt-layer/components/HelloWorld.vue:

image

For the above reason, I am manually typing runtime config (again, as per nuxt docs) inside the module testModule.ts.

image

It seems to do what I want - I do get typecheck and IntelliSense inside my layer.

image

The problem is - it is also causing an error inside an app extending the layer:

Screenshot 2023-07-22 at 15 16 42

It seems to be a bug for me. I have not figured out a way to get the types working both in the layer and the app extending my layer*.

* well, to be honest, for some reason it does seem to work if I add package.json in the root of my repo, configure it to be a monorepo, and run npm i from this root. But I don't think it is always a solution. I don't want to put my app and layer in a monorepo.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions