Skip to content

fix(nitro): expose server auto-imports as #imports/server - #36039

Closed
chairulakmal wants to merge 3 commits into
nuxt:mainfrom
chairulakmal:fix/33979-server-imports-alias
Closed

chairulakmal wants to merge 3 commits into
nuxt:mainfrom
chairulakmal:fix/33979-server-imports-alias

Conversation

@chairulakmal

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #33979

📚 Description

Nitro now registers a #imports/server alias pointing at the nitro-imports.d.ts it already generates, so server auto-imports can be imported explicitly from a specifier that resolves in every type context. It's mapped in tsconfig.server.json and, through the prepare:types hook, in tsconfig.app.json, which the legacy .nuxt/tsconfig.json inherits; at runtime it's a Nitro virtual entry re-exporting #imports, the same way Nitro already exposes #nitro. Deliberately not a nuxt.options.alias entry, so importing it from app code still fails the build instead of bundling server code into the client.

It needs a second name because nitro-routes.d.ts imports route handlers for $fetch return-type inference, which pulls server files into the app program, and there #imports is the app's auto-imports with nothing from addServerImports declared. Since #35938 the server imports run regardless of experimental.nitroAutoImports, so this hits default v5 apps. Plain #imports in a server file stays broken in the app program and this PR doesn't change that: one specifier can't resolve to two different sets in two programs that both include the file.

On naming, I said I'd wait for your confirmation before opening this. I went with #imports/server since it's the wording in the issue, but it's trivial to rename and the #imports/nuxt + #imports/nitro pair is still on the table.

Tests cover the tsconfig paths, the runtime virtual and the absence of an app alias, plus type-level fixtures for a route handler and a non-route server file and a runtime $fetch assertion; docs updated in the auto-imports guide, the module recipes page and the Kit Nitro reference.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c251fabb-4ff8-4b17-a44e-72a008299b48

📥 Commits

Reviewing files that changed from the base of the PR and between bf6fba6 and 0954189.

📒 Files selected for processing (1)
  • docs/4.api/5.kit/12.nitro.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/4.api/5.kit/12.nitro.md

Walkthrough

Nuxt and Nitro expose server auto-imports through the #imports/server alias. Nitro generates server and application TypeScript mappings without adding a client runtime alias. Tests cover type generation, virtual modules, typed server imports, and runtime responses. Documentation describes module registration, server-route usage, and server-only scope.

Possibly related PRs

  • nuxt/nuxt#35697: Both changes update TypeScript configuration generation and related tests.
  • nuxt/nuxt#35813: Both changes update server auto-import registration and type-generation documentation.
  • nuxt/nuxt#36011: Both changes update Nitro generated TypeScript path aliases and loadNuxt coverage.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: exposing Nitro server auto-imports through the #imports/server alias.
Description check ✅ Passed The description directly explains the alias implementation, type resolution, runtime behaviour, tests, and documentation changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/4.api/5.kit/12.nitro.md`:
- Around line 304-305: Update the documentation sentence describing the
`#imports/server` alias so it claims support only in the app and server type
contexts, preserving the existing server-route example and avoiding broader
claims about every type context.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f91a185f-3f9b-4d93-a7bc-68e249c54e4e

📥 Commits

Reviewing files that changed from the base of the PR and between d214194 and bf6fba6.

📒 Files selected for processing (12)
  • docs/3.guide/1.concepts/3.auto-imports.md
  • docs/3.guide/4.modules/5.recipes-advanced.md
  • docs/4.api/5.kit/12.nitro.md
  • packages/kit/test/generate-types.spec.ts
  • packages/nitro-server/src/index.ts
  • packages/nuxt/test/load-nuxt.test.ts
  • test/basic.test.ts
  • test/fixtures/basic-types/modules/auto-registered/index.ts
  • test/fixtures/basic-types/modules/auto-registered/runtime/server/utils/session.ts
  • test/fixtures/basic-types/server/api/server-imports.ts
  • test/fixtures/basic-types/server/utils/server-imports.ts
  • test/fixtures/basic/server/api/server-imports.ts

Comment thread docs/4.api/5.kit/12.nitro.md Resolved
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

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

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@36039

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: b925b3f

@codspeed

codspeed Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing chairulakmal:fix/33979-server-imports-alias (b925b3f) with main (cdbd3d1)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@danielroe

Copy link
Copy Markdown
Member

this was a good change - thank you ❤️

however, nitro v3 has now dropped auto-imports entirely, so this is resolved #36265 🎉

@danielroe danielroe closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App context type-checking server files causes it to fail when importing from #imports

2 participants