Skip to content

Typecheck fails to find Nitro globals when shared/ imports a type from server/ #32885

@IlyaSemenov

Description

@IlyaSemenov

Environment

  • Operating System: Linux
  • Node Version: v20.19.1
  • Nuxt Version: 4.0.3
  • CLI Version: 3.27.0
  • Nitro Version: 2.12.4
  • Package Manager: pnpm@8.15.6
  • Builder: -
  • User Config: compatibilityDate, devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-etiwf36j

Run:

pnpm nuxt typecheck

Describe the bug

With the latest Nuxt 4 typescript layout (including the new single composite tsconfig.json in the project root), the following file structure:

  • server/something.ts imports useRuntimeConfig (or any other nitro global) and exports some type
  • shared/something.ts imports a type from ~~/server/something

somehow confuses the type checker, so that it stops recognizing nitro globals under server/.

Everything works in runtime, and there are no type errors in IDE. Removing the cross-boundary type import fixes the type check for nitro globals again.

Additional context

I believe this is a perfectly valid scenario when app/ or shared/ imports a type from server/, for working with data coming from the server. It used to work fine with Nuxt 3. It works fine with app/ in Nuxt 4, only breaks with shared/.

Logs

> nuxt typecheck

server/auth.ts:1:23 - error TS2304: Cannot find name 'useRuntimeConfig'.

1 export const config = useRuntimeConfig()
                        ~~~~~~~~~~~~~~~~


Found 1 error.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions