Skip to content

fix: avoid nitro v2 compatibility layer on nitro 3 - #3937

Open
larbish wants to merge 1 commit into
v4from
fix/nitro-3-compat-layer
Open

larbish wants to merge 1 commit into
v4from
fix/nitro-3-compat-layer

Conversation

@larbish

@larbish larbish commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

On Nitro 3 (Nuxt 5, or Nuxt 4 with nitro and @nuxt/nitro-v3-server installed), the module made Nuxt apply its Nitro v2 compatibility layer and warn about the module itself:

  • NUXT_B9003: the module's server code imports nitropack/runtime and #imports.
  • NUXT_B9001: the module sets nitro.esbuild, which Nitro 3 ignores.
  • NUXT_B9002, on Nuxt 4 only: the media middleware has no route.

What changed:

  • Snapshot loaders: they read server assets through a #content/storage alias. resolveServerVariant points it at nitro/storage on Nitro 3 and at nitropack/runtime on Nitro 2.
  • v3 server composables: v3/composables.server.ts imports content from a #content/server alias instead of #imports. Its nuxt/server import is type-only, so it is stripped from dist and Nuxt flagged the file.
  • nitro.esbuild: only set on Nitro 2. Nitro 3 already targets esnext.
  • Media middleware: it gets route: '/**' on Nitro 3. Nitro 2 reads route as a prefix, so it still gets none there.
  • Types: a generated content/aliases.d.ts declares both aliases for the app tsconfig.
  • Tests: test/nitro3.test.ts runs nuxt prepare and nuxt build on two fixtures, nuxt5 (pinned nightly) and nuxt4-nitro3. It fails on NUXT_B9001, NUXT_B9002 or NUXT_B9003. Each fixture has its own lockfile, and CI installs both before vitest.

Evidence

nuxt build of the same app, with the published v4 build (50232f9) as Before and this branch packed as After.

Nuxt 5, Before:

● Nuxt 5.0.0-2611271344-0b7a0bd (with Nitro 3.0.261103-rc, Vite 8.4.0 and Vue 3.5.46)
 WARN  [NUXT_B9001] The following nitro config options are no longer supported by Nitro v3 and were ignored: esbuild.
 WARN  [NUXT_B9003] Nitro v2 compatibility was applied to server code from 1 module, because of what it imports:
  - @nuxt/content (imports #imports, nitropack/runtime)
◆ Build complete in 2.53s

Nuxt 5, After:

● Nuxt 5.0.0-2611271344-0b7a0bd (with Nitro 3.0.261103-rc, Vite 8.4.0 and Vue 3.5.46)
◆ Build complete in 3.30s

Nuxt 4.7 + Nitro 3, Before:

● Nuxt 4.7.0 (with Nitro 3.0.261103-rc, Vite 8.4.0 and Vue 3.5.46)
 WARN  [NUXT_B9001] The following nitro config options are no longer supported by Nitro v3 and were ignored: esbuild.
 WARN  [NUXT_B9002] 1 Nitro v2 handler has no route, which Nitro v3 requires:
  - @nuxt/content/dist/runtime/server/internal/assets-middleware
 WARN  [NUXT_B9003] Nitro v2 compatibility was applied to server code from 1 module, because of what it imports:
  - @nuxt/content (imports #imports, nitropack/runtime)
◆ Build complete in 3.06s

Nuxt 4.7 + Nitro 3, After:

● Nuxt 4.7.0 (with Nitro 3.0.261103-rc, Vite 8.4.0 and Vue 3.5.46)
◆ Build complete in 3.31s

nuxt prepare on Nuxt 5 prints the same B9001 and B9003 before, and nothing after. With content/ deleted, the production server still renders the page from the snapshot and serves a media file (200 image/png) on Nuxt 4.7 + Nitro 2, Nuxt 4.7 + Nitro 3 and Nuxt 5.

test/nitro3.test.ts (both fixtures, prepare and build):

 Test Files  1 passed (1)
      Tests  4 passed (4)

Lint, prepack and typecheck pass, and the full vitest suite passes on Nuxt 4.7.

Notes

  • Pinned fixtures: they pin [email protected] and [email protected], so bump them by hand until both are released.
  • What the test can't catch: vitest runs against the stubbed dist, which links to src, so it can't catch a type-only nuxt/server import being stripped from dist. That case was checked with a packed tarball.
  • Nuxt 4 still turns the layer on: Nuxt 4 enables nitroLegacy by default on Nitro 3, so the layer stays on for the app as a whole there. The module no longer needs it.

ELI5

Newer Nuxt servers have a slower fallback for old code, and they used it for Nuxt Content because of a few old-style imports and settings. The module now ships a small file for each server version and picks the right one. New servers run it directly, and older ones work as before.

🤖 Generated with Amp, reviewed by @larbish before opening.

@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
content Error Error Nov 28, 2026 1:08pm UTC

Request Review

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednitro@​3.0.261103-rc991008291100
Addednuxt-nightly@​5.0.0-2611271344-0b7a0bd9710010096100

View full report

@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The module now selects storage implementations and related type declarations by Nitro version. Its esbuild target and media middleware route also vary by Nitro version. The change adds Nuxt 4/Nitro 3 and Nuxt 5 fixtures, installs their dependencies in CI, and tests their prepare and build commands for specified warning codes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: Minimal · up to 14886 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the module avoids the Nitro v2 compatibility layer when running on Nitro 3. The changeset adds Nitro 3 aliases, moves composables to #content/server, and sets nitro.es…
Description check Passed The description explains the warnings (NUXT_B9001, NUXT_B9002, NUXT_B9003) and lists each code change: the storage alias, the v3 composables import, the nitro.esbuild gating, the media middleware rout…
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.
Full details: Title check

Explanation

The title names the main change: the module avoids the Nitro v2 compatibility layer when running on Nitro 3. The changeset adds Nitro 3 aliases, moves composables to #content/server, and sets nitro.esbuild only on Nitro 2. The title is short, specific, and follows the conventional commit style.

Full details: Description check

Explanation

The description explains the warnings (NUXT_B9001, NUXT_B9002, NUXT_B9003) and lists each code change: the storage alias, the v3 composables import, the nitro.esbuild gating, the media middleware route, the generated aliases.d.ts types, and the new test. It also gives build evidence and notes on pinned fixtures. It matches the changeset closely.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

nitro-storage.d.ts

Parsing error: Unexpected token module

src/module.ts

Parsing error: Unexpected token {

src/runtime/server/content.ts

Parsing error: Unexpected token CacheArtifact

  • 1 others

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c92fb343-017e-4145-8574-d80504bb2742
Commits

Reviewing files that changed from the base of the PR and between 50232f9 and 148863f.

Files ignored due to path filters: 2

  • test/fixtures/nuxt4-nitro3/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • test/fixtures/nuxt5/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 19

  • .github/workflows/ci.yml
  • nitro-storage.d.ts
  • src/module.ts
  • src/runtime/server/content.ts
  • src/runtime/server/internal/storage.legacy.ts
  • src/runtime/server/internal/storage.ts
  • src/runtime/v3/composables.server.ts
  • src/utils/templates.ts
  • test/fixtures/nuxt4-nitro3/app.vue
  • test/fixtures/nuxt4-nitro3/content/index.md
  • test/fixtures/nuxt4-nitro3/nuxt.config.ts
  • test/fixtures/nuxt4-nitro3/package.json
  • test/fixtures/nuxt4-nitro3/pnpm-workspace.yaml
  • test/fixtures/nuxt5/app.vue
  • test/fixtures/nuxt5/content/index.md
  • test/fixtures/nuxt5/nuxt.config.ts
  • test/fixtures/nuxt5/package.json
  • test/fixtures/nuxt5/pnpm-workspace.yaml
  • test/nitro3.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 28, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3937

commit: 148863f

This branch had an error being deployed

1 failed deployment
Preview — 148863fa Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant