Skip to content

docs: add reason for why you should never import Vue app code in nitro code - #34481

Merged
danielroe merged 5 commits into
nuxt:mainfrom
Ibochkarev:docs/30862-vue-nitro-import-explanation
Jul 19, 2026
Merged

danielroe merged 5 commits into
nuxt:mainfrom
Ibochkarev:docs/30862-vue-nitro-import-explanation

Conversation

@Ibochkarev

Copy link
Copy Markdown
Contributor

Add documentation explaining why Vue app code must not be imported in Nitro (and vice versa), as requested in #30862. The docs previously stated the rule but did not give reasons, which led users to ignore it or rely on type-only imports without a clear boundary.

Changes:

  • shared/ docs: New section "Why you cannot mix Vue and Nitro code" describing separate bundles and runtimes, what breaks when importing Vue in Nitro (no Nuxt context, wrong bundle) and Nitro in Vue (server-only code in client, bundle size). Explicit note that code in shared/ cannot import Vue/Nitro for the same reasons. Clarification that Vue components and composables cannot run in Nitro. Subsection on type-only imports: import type is erased at compile time so it may appear to work, but shared types should live in shared/types/ for a clear boundary and to avoid accidentally turning them into value imports. Example for API/GraphQL types in shared/types/.
  • server/ docs: ::important block warning not to import Vue app code (including components and composables) in server routes/utilities, and not to import server-only code in the app, with a link to the full explanation in the shared/ docs.

Fixes #30862

@Ibochkarev
Ibochkarev requested a review from danielroe as a code owner March 9, 2026 08:06
@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 5.x 📚 documentation Documentation improvements or additions labels Mar 9, 2026
@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The changes add documentation clarifying the runtime separation between Vue/Nuxt app code and Nitro server code. One file inserts an advisory callout warning not to import Vue/Nuxt app-only code into server routes/utilities and not to import server-only/Nitro code into the app. Another file explains the dual-bundle architecture, states that shared/ code must not import Vue or Nitro runtime artifacts, clarifies type-only import semantics, and recommends centralising shared types under shared/types and importing them via the #shared alias. No code or exported signatures were changed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main documentation change and clearly states the reason being added.
Description check ✅ Passed The description is directly related to the docs changes and accurately summarises the motivation and scope.
Linked Issues check ✅ Passed The docs explain the Vue/Nitro boundary, consequences, type-only imports, shared types, and update the relevant sections as requested in #30862.
Out of Scope Changes check ✅ Passed The changes stay within the requested documentation scope and do not introduce unrelated edits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/2.directory-structure/1.shared.md`:
- Line 18: Promote the heading "Why you cannot mix Vue and Nitro code" from
level ### to level ## so it becomes a peer of "## Usage" (replace the existing
"### Why you cannot mix Vue and Nitro code" with "## Why you cannot mix Vue and
Nitro code"); this will correct the heading level and stop MD001 lint warnings.
- Around line 24-25: The docs incorrectly list useRuntimeConfig() as an app-only
API; replace that example with a truly app-only API (e.g. useRoute() or
useState()) or remove it so only useNuxtApp() is shown. Update the sentence that
currently references useRuntimeConfig() to instead reference the chosen app-only
symbol (useRoute() or useState()), ensuring the doc no longer implies
useRuntimeConfig() cannot be used in server handlers (useRuntimeConfig(event) is
valid server-side).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 188eef23-8461-4160-b889-900a309b1529

📥 Commits

Reviewing files that changed from the base of the PR and between fea006d and 86e3cdd.

📒 Files selected for processing (2)
  • docs/2.directory-structure/1.server.md
  • docs/2.directory-structure/1.shared.md

Comment thread docs/2.directory-structure/1.shared.md Resolved
Comment thread docs/2.directory-structure/1.shared.md Resolved

@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.

🧹 Nitpick comments (1)
docs/2.directory-structure/1.shared.md (1)

38-38: Clarify the type-checking explanation.

The phrase "server routes are type-checked from both app and server tsconfigs" could mislead readers into thinking server routes undergo two separate type-checking passes. The intended meaning appears to be that shared types work predictably when imported into either context (server code checked with server tsconfig, app code with app tsconfig).

📝 Suggested clarification
-- Type-checking and tooling stay predictable (e.g. server routes are type-checked from both app and server tsconfigs).
+- Type-checking and tooling stay predictable in both contexts (server routes with server tsconfig, app code with app tsconfig).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/2.directory-structure/1.shared.md` at line 38, Rewrite the sentence to
clarify that shared types are usable from either context and that each context
is type-checked under its own tsconfig (e.g., "server code is type-checked with
the server tsconfig and app code with the app tsconfig, so shared types imported
into either context behave predictably"), replacing the ambiguous "server routes
are type-checked from both app and server tsconfigs" phrase.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/2.directory-structure/1.shared.md`:
- Line 38: Rewrite the sentence to clarify that shared types are usable from
either context and that each context is type-checked under its own tsconfig
(e.g., "server code is type-checked with the server tsconfig and app code with
the app tsconfig, so shared types imported into either context behave
predictably"), replacing the ambiguous "server routes are type-checked from both
app and server tsconfigs" phrase.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d36a7f0b-2735-4bb9-8736-490215b2a080

📥 Commits

Reviewing files that changed from the base of the PR and between 86e3cdd and 03f0574.

📒 Files selected for processing (1)
  • docs/2.directory-structure/1.shared.md

@Ibochkarev
Ibochkarev force-pushed the docs/30862-vue-nitro-import-explanation branch from 03f0574 to e278bab Compare April 21, 2026 05:18
…o code

- Add 'Why you cannot mix Vue and Nitro code' section in shared/ docs
- Explain separate bundles, runtimes, and consequences of cross-imports
- Clarify type-only imports and recommend shared/types/ for shared types
- Add warning and link in server/ docs (both directions: Vue in Nitro, Nitro in Vue)

Fixes nuxt#30862
- Change heading level for clarity
- Update explanation regarding the context of Vue app code and Nitro imports
- Emphasize the importance of avoiding cross-imports to prevent runtime errors
@Ibochkarev
Ibochkarev force-pushed the docs/30862-vue-nitro-import-explanation branch from e278bab to d7b5cd1 Compare May 25, 2026 17:28
@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

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

@nuxt/nitro-server

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: d5f7fca

@danielroe
danielroe enabled auto-merge July 19, 2026 10:42
@danielroe
danielroe added this pull request to the merge queue Jul 19, 2026
Merged via the queue into nuxt:main with commit ae99a94 Jul 19, 2026
21 of 22 checks passed
@Ibochkarev
Ibochkarev deleted the docs/30862-vue-nitro-import-explanation branch July 19, 2026 11:54
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
2 of 5 tasks
danielroe added a commit that referenced this pull request Jul 20, 2026
…o code (#34481)

Co-authored-by: Daniel Roe <[email protected]>
(cherry picked from commit ae99a94)
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
danielroe added a commit that referenced this pull request Jul 20, 2026
…o code (#34481)

Co-authored-by: Daniel Roe <[email protected]>
(cherry picked from commit ae99a94)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 📚 documentation Documentation improvements or additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: add reason for why you should never import Vue app code in your nitro code

2 participants