Skip to content

nuxt typecheck with -b flag fails to resolve declare global auto-imports #1224

@LePtiDev

Description

@LePtiDev

Description

nuxt typecheck uses vue-tsc -b --noEmit when the root tsconfig.json contains references (which is the default in Nuxt 4 since PR nuxt/nuxt#30665). However, vue-tsc in build mode (-b) does not properly resolve declare global type declarations from .nuxt/types/imports.d.ts across TypeScript project references.

This results in hundreds of false-positive "Cannot find name" errors for all Nuxt auto-imports (ref, computed, useRoute, navigateTo, definePageMeta, etc.).

Reproduction

  1. Create a fresh Nuxt 4 project (or any Nuxt project where tsconfig.json has references)
  2. Run nuxt typecheck
  3. Observe hundreds of TS2304: Cannot find name '...' errors on all auto-imported items

Expected behavior

nuxt typecheck should report only real type errors.

Actual behavior

vue-tsc -b --noEmit reports ~900 errors, most of which are false-positive "Cannot find name" errors on auto-imports.

Running vue-tsc --noEmit -p .nuxt/tsconfig.json (without -b) correctly reports only ~40 real errors.

Root cause

In packages/nuxi/src/commands/typecheck.ts:

const supportsProjects = !!(tsconfig.references?.length)
const typeCheckArgs = supportsProjects ? ['-b', '--noEmit'] : ['--noEmit']

When -b is used, vue-tsc treats each project reference as an isolated compilation unit. The declare global block in .nuxt/types/imports.d.ts (which declares all auto-imports) is not visible across project boundaries, causing every auto-imported symbol to be unresolved.

Workaround

Replace nuxt typecheck with a direct vue-tsc invocation in package.json:

"typecheck": "nuxt prepare && vue-tsc --noEmit -p .nuxt/tsconfig.json"

This bypasses the -b flag while still pointing to the correct tsconfig that includes the auto-import declarations.

Environment

  • Nuxt: 4.3.0
  • @nuxt/cli: 3.32.0
  • vue-tsc: 2.2.12
  • TypeScript: 5.9.3
  • Package manager: bun

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions