Skip to content

Conversation

@dheeraj3587
Copy link

Fixes #33477

In Nuxt 4.1.3, server files inside layer directories (e.g. layers/*/server/**) were not being included in the generated .nuxt/tsconfig.server.json. This caused TypeScript errors in IDEs such as WebStorm (e.g. Cannot find name 'defineNitroPlugin'), even though the application ran correctly.

This change updates the TypeScript configuration generation to automatically include all layer server directories, matching how Nitro already includes them in its scanDirs configuration.

Changes

  • Added layer server paths to the include array in .nuxt/tsconfig.server.json
  • Restored IDE TypeScript support for server files inside layers
  • Removed the need for manual configuration via nitro.typescript.tsConfig.include

Linked issue

Fixes #33477

Notes

This aligns the handling of layer server directories with the main server directory, improving TypeScript developer experience without affecting runtime behavior.

Fixes an issue where server files inside Nuxt layer directories
(e.g., layers/*/server/**) were not automatically included in
.nuxt/tsconfig.server.json, causing IDEs to fail type resolution
for Nitro types like defineNitroPlugin.

Changes:
- Add layer server directories to Nitro TypeScript config include
- Add test to verify layer server paths are included in tsconfig

Closes  nuxt#33489
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Walkthrough

Adds additional TypeScript/JavaScript include globs to the Nitro/Nuxt server build so Nitro's tsconfig include array also contains server files from layer directories (appends for each layer's server dir the globs **/*.{ts,tsx,mts,cts,js,mjs,cjs} via relativeWithDot). Adds a test that loads Nuxt with a layers fixture, reads Nitro's tsconfig include entries from Nuxt's internal _nitro options, and asserts a layer server path (e.g. layers/auto/server) is present. No runtime logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix(nitro): include layer server directories in tsconfig.server.json" is clear, specific, and directly summarises the main change in the changeset. It uses conventional commit format and accurately describes the core objective of including layer server directories in the TypeScript configuration, making it immediately understandable to teammates reviewing the history.
Linked Issues Check ✅ Passed The changeset addresses the primary objective from linked issue #33477. The modification to packages/nitro-server/src/index.ts implements the automatic inclusion of layer server directories in the TypeScript configuration by expanding the include array with server file globs for each layer's server directory. The addition of a test in packages/nuxt/test/load-nuxt.test.ts verifies that layer server directories are correctly included. Both changes fulfil the requirement to restore IDE TypeScript support for server files inside layers without manual configuration workarounds.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly aligned with the scope of fixing issue #33477. The modification to packages/nitro-server/src/index.ts adds the necessary TypeScript include paths for layer server directories, and the test addition in packages/nuxt/test/load-nuxt.test.ts validates the fix. No extraneous changes, unrelated refactoring, or functionality outside the stated objectives are present in the changeset.
Description Check ✅ Passed The pull request description is clearly related to the changeset. It provides context about the issue (server files in layer directories not being included in tsconfig.server.json), explains the solution applied, lists the changes made, and includes a reference to the linked issue. The description conveys meaningful information about the problem being solved and how it affects the developer experience.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 918baf7 and 74f5823.

📒 Files selected for processing (1)
  • packages/nitro-server/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nitro-server/src/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: code
  • GitHub Check: build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 934dc00 and de4c796.

📒 Files selected for processing (2)
  • packages/nitro-server/src/index.ts (1 hunks)
  • packages/nuxt/test/load-nuxt.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nitro-server/src/index.ts
  • packages/nuxt/test/load-nuxt.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/nuxt/test/load-nuxt.test.ts
🧬 Code graph analysis (1)
packages/nuxt/test/load-nuxt.test.ts (2)
packages/nuxt/src/core/nuxt.ts (1)
  • loadNuxt (752-870)
packages/kit/src/loader/nuxt.ts (1)
  • loadNuxt (18-37)
🪛 GitHub Check: build
packages/nuxt/test/load-nuxt.test.ts

[failure] 149-149:
Property '_nitro' does not exist on type 'Nuxt'.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: code
🔇 Additional comments (1)
packages/nitro-server/src/index.ts (1)

217-217: LGTM! Correctly includes layer server directories in TypeScript configuration.

This change aligns TypeScript IDE support with Nitro's runtime scanDirs behaviour (line 180), ensuring server files within layers receive proper type checking. The glob pattern **/* appropriately captures all server files, consistent with the objective to fix IDE TypeScript errors for layer server directories.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 18, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33510

nuxt

npm i https://pkg.pr.new/nuxt@33510

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33510

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33510

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33510

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33510

commit: 74f5823

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 18, 2025

CodSpeed Performance Report

Merging #33510 will not alter performance

Comparing dheeraj3587:main (74f5823) with main (ba0dfeb)

Summary

✅ 10 untouched

The '**/*' glob was causing TypeScript to process all files including non-TS files, leading to performance issues and test timeouts. Changed to match the pattern used for module directories.
Changed from 'dirs.server' to 'dirs.server/**/*.{ts,tsx,mts,cts}'
- Ensures subdirectories like server/api/, server/middleware/ are included
- Only processes TypeScript files, avoiding performance issues
- Matches pattern used for shared directories
]
}),
...layerDirs.flatMap((dirs) => {
const serverFileGlobs = ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts', '**/*.js', '**/*.mjs', '**/*.cjs']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we add just the server directory and not the individual extensions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Layer server files not included in .nuxt/tsconfig.server.json in Nuxt 4.1.3

3 participants