Skip to content

generateTsConfig produces alternating results due to incorrect tsconfig merging #3945

@schplitt

Description

@schplitt

Environment

nitro: 3.0.1-alpha.1
node: 24.13.0

Reproduction

https://stackblitz.com/edit/vitejs-vite-ecblczws?file=tsconfig.json

(generatedTypesDir set as stackblitz doesn't show node_modules folder, found issue there is similar)

Describe the bug

When typescript.generateTsConfig: true is set, running pnpm nitro prepare multiple times produces alternating/inconsistent results. The generated tsconfig.json in node_modules/.nitro/types/ incorrectly merges the project's root tsconfig.json, causing the extends field and other properties to appear and disappear on alternating runs.

Expected Behavior

The generated node_modules/.nitro/types/tsconfig.json should be consistent on every run and should not include properties from the project's root tsconfig.json (such as extends, custom include paths, etc.).

Actual Behavior

The generated tsconfig alternates between:

  • Clean output with only Nitro's defaults
  • Merged output containing the project's extends field and other properties which results in a circular tsconfig / tsconfig not found

Workaround

Explicitly set tsConfig: {} in nitro.config.ts to prevent false extends fields:

export default defineConfig({
  typescript:  {
    generateTsConfig:  true,
    tsConfig:  {} // Prevents loading root tsconfig and circular extends
  }
});

The issue appears to be in src/config/resolvers/tsconfig.ts where the user's project tsconfig.json is loaded and used to generate Nitro's internal tsconfig. When the project's tsconfig contains extends: [".nitro/types/tsconfig"], this creates a circular dependency: the generated config ends up extending itself or not finding the extended one.

Additional context

No response

Logs

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