-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Open
Copy link
Labels
Description
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
importsuseRuntimeConfig
(or any other nitro global) and exports some typeshared/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.
aerophobic