Skip to content

fix(nuxt): include shared types in tsconfig.server.json - #32594

Merged
danielroe merged 1 commit into
nuxt:mainfrom
stephenjason89:fix/tsconfig
Jul 14, 2025
Merged

danielroe merged 1 commit into
nuxt:mainfrom
stephenjason89:fix/tsconfig

Conversation

@stephenjason89

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #32593

Problem

The generated .nuxt/tsconfig.server.json was missing the shared types include pattern (../shared/**/*.d.ts), while tsconfig.json and tsconfig.app.json correctly included it. This prevented types in the shared/ directory from being available in server routes, breaking type sharing between client and server.

Solution

Added the shared types pattern to the server tsconfig generation in packages/nuxt/src/core/nitro.ts to match the pattern used in tsconfig.app.json.

Changes

  • Added shared types include pattern for each layer in the server tsconfig generation
  • Matches the existing pattern used in tsconfig.app.json: ../shared/**/*.d.ts
  • Ensures parity between client and server type availability

Before

// .nuxt/tsconfig.server.json
{
  "include": [
    "./types/nitro-nuxt.d.ts",
    ".../devtools/runtime/server",
    // ❌ Missing shared types
  ]
}

After

// .nuxt/tsconfig.server.json
{
  "include": [
    "./types/nitro-nuxt.d.ts",
    ".../devtools/runtime/server",
    "../shared/**/*.d.ts"  // ✅ Now included
  ]
}

Testing

  • ✅ Verified shared types are now included in generated tsconfig.server.json
  • ✅ Confirmed type sharing works between client and server routes
  • ✅ No breaking changes to existing functionality

Related

Fixes issue where server routes could not access types defined in shared/ directory.


Type: Bug Fix
Breaking Change: No
Testing: Manual verification with local Nuxt build

@bolt-new-by-stackblitz

Copy link
Copy Markdown

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

@github-actions github-actions Bot added 4.x 🐛 bug Something isn't working as expected labels Jul 12, 2025
@coderabbitai

coderabbitai Bot commented Jul 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The update modifies the Nitro setup in Nuxt by adding new TypeScript declaration file paths to the include array within the typescript.tsConfig configuration. It achieves this by iterating over each Nuxt layer in nuxt.options._layers, resolving the path to the shared directory (defaulting to 'shared' if not specified), and including all .d.ts files found recursively within these directories. The resulting paths are made relative to the build directory using relativeWithDot. No changes are made to exported or public entities.


📜 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 93fbde5 and 1a7ad36.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/nitro.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/nuxt/src/core/nitro.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). (4)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: codeql (actions)
  • GitHub Check: build
  • GitHub Check: code
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/nuxt/src/core/nitro.ts (1)

143-148: Include pattern works; consider deduplication + early validation

The newly-added mapping correctly adds shared/**/*.d.ts files to the server tsconfig, solving the missing-types issue. Two optional improvements:

  1. If several layers share the same physical shared directory (common in monorepos), the resulting array may contain duplicate entries. Wrapping the map result in new Set(...) (or pushing into a Set first) will keep the tsconfig tidier.
  2. A quick existsSync() guard can prevent pointing TypeScript at non-existent paths when a layer omits shared, avoiding unnecessary work during language-service initialisation.

Example:

- ...nuxt.options._layers.map(layer =>
-   relativeWithDot(
-     nuxt.options.buildDir,
-     resolve(layer.config.rootDir, layer.config.dir?.shared ?? 'shared', '**/*.d.ts'),
-   ),
- ),
+ ...Array.from(
+   new Set(
+     nuxt.options._layers
+       .map(layer => resolve(layer.config.rootDir, layer.config.dir?.shared ?? 'shared', '**/*.d.ts'))
+       .filter(p => existsSync(p.replace(/\/\*\*\/\*\.d\.ts$/, ''))) // drop non-existent dirs
+   ),
+ ).map(p => relativeWithDot(nuxt.options.buildDir, p)),

Purely an optimisation; feel free to ignore if the current solution already meets your needs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30a3cc6 and 93fbde5.

⛔ Files ignored due to path filters (6)
  • packages/kit/package.json is excluded by !**/package.json
  • packages/nuxt/package.json is excluded by !**/package.json
  • packages/rspack/package.json is excluded by !**/package.json
  • packages/schema/package.json is excluded by !**/package.json
  • packages/vite/package.json is excluded by !**/package.json
  • packages/webpack/package.json is excluded by !**/package.json
📒 Files selected for processing (1)
  • packages/nuxt/src/core/nitro.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .github/copilot-instructions.md
**/*.{ts,tsx,vue}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .github/copilot-instructions.md
🧠 Learnings (2)
📓 Common learnings
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components
Learnt from: TheAlexLichter
PR: nuxt/nuxt#31812
File: packages/nuxt/src/components/plugins/islands-transform.ts:202-202
Timestamp: 2025-04-18T18:33:41.753Z
Learning: In Nuxt, using `rolldownVersion` (not `rollupVersion`) is intentional when detecting if rolldown-vite is being used, even though TypeScript may show an error because the property isn't in standard type definitions yet.
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.{ts,tsx} : Follow standard TypeScript conventions and best practices
Learnt from: GalacticHypernova
PR: nuxt/nuxt#29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.
packages/nuxt/src/core/nitro.ts (6)
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.{ts,tsx} : Follow standard TypeScript conventions and best practices
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Learnt from: GalacticHypernova
PR: nuxt/nuxt#29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.{ts,tsx,vue} : Add comments only to explain complex logic or non-obvious implementations
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T13:48:28.134Z
Learning: Applies to **/*.{ts,tsx,vue} : Remove code that is not used or needed
⏰ 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). (1)
  • GitHub Check: Socket Security: Pull Request Alerts

@stephenjason89 stephenjason89 changed the title fix(nitro): include shared types in tsconfig.server.json fix(nuxt): include shared types in tsconfig.server.json Jul 12, 2025
@stephenjason89
stephenjason89 changed the base branch from main to v4.0.0 July 12, 2025 15:57
@danielroe
danielroe changed the base branch from v4.0.0 to main July 13, 2025 15:52
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2025

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 1a7ad36

@codspeed

codspeed Bot commented Jul 13, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #32594 will not alter performance

Comparing stephenjason89:fix/tsconfig (1a7ad36) with main (53f2acd)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe mentioned this pull request Jul 7, 2025
6 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v4 tsconfig.server.json missing shared types include pattern

2 participants