-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(nitro): include layer server directories in tsconfig.server.json #33510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
|
|
WalkthroughUpdates Nitro/Nuxt build configuration to append TypeScript/JavaScript include globs for each layer's Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
📒 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.tspackages/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
scanDirsbehaviour (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.
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33510 will not alter performanceComparing Summary
|
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
packages/nitro-server/src/index.ts
Outdated
| ] | ||
| }), | ||
| ...layerDirs.flatMap((dirs) => { | ||
| const serverFileGlobs = ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts', '**/*.js', '**/*.mjs', '**/*.cjs'] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- extensions are configureable from options: example knip https://github.com/webpro-nl/knip/pull/1265/files#diff-94cc8dab409c9b7cd7fc21a94d45b1fd23f3fd3c5eb2a152dea271fa1bbeff59R44
- we can combine them into one glob: https://github.com/webpro-nl/knip/pull/1265/files#diff-94cc8dab409c9b7cd7fc21a94d45b1fd23f3fd3c5eb2a152dea271fa1bbeff59R90
danielroe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nitro-server/src/index.ts (1)
218-218: Consider using specific file extensions in the glob pattern.Following up on the previous discussion, the current pattern
**/*matches all files in layer server directories. For better precision and clarity, consider restricting to server code file extensions.Based on coding guidelines, this would be clearer and avoid including non-code files (JSON, markdown, etc.):
- ...layerDirs.map(dirs => relativeWithDot(nuxt.options.buildDir, join(dirs.server, '**/*'))), + ...layerDirs.map(dirs => relativeWithDot(nuxt.options.buildDir, join(dirs.server, '**/*.{ts,tsx,mts,cts,js,mjs,cjs}'))),This aligns with TypeScript best practices and matches the typical server file extensions that Nitro would scan.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nitro-server/src/index.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nitro-server/src/index.ts
**/*.{ts,tsx,js,jsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently
Files:
packages/nitro-server/src/index.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.119Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js} : Write unit tests for core functionality using `vitest`
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
scanDirsconfiguration.Changes
includearray in.nuxt/tsconfig.server.jsonnitro.typescript.tsConfig.includeLinked 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.