cloudflare/vinext

Build failure: `server-only` incorrectly blocked in middleware (SSR environment)

Geschlossen

#1.344 geöffnet am 20.05.2026

 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (383 Forks)github user discovery
adapter-api-e2ehelp wanted

Repository-Metriken

Stars
 (8.624 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 1h) (462 gemergte PRs in 30 T)

Beschreibung

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).

Problem

Middleware runs server-side and should be allowed to import server-only. However, vinext bundles middleware into the SSR environment, and the @vitejs/plugin-rsc rsc:validate-imports plugin flags server-only as invalid in non-RSC environments.

[plugin rsc:validate-imports] middleware.js
Error: 'server-only' cannot be imported in client build ('ssr' environment):
 imported by middleware.js
   imported by virtual:vinext-server-entry

1 build failure cascades to 13 test failures because the entire test app fails to build.

Estimated Impact

~13 test failures (from 1 build failure).

Affected Test Suites

  • test/e2e/module-layer/module-layer.test.ts (13 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a test with a middleware file that imports server-only and verify the build succeeds. Confirm it currently fails.

  2. Exclude middleware from the server-only validation. Either configure the RSC plugin to allow server-only in the SSR environment when imported by middleware, or move middleware to a server-appropriate build environment.

  3. Study how Next.js handles middleware module layers. In Next.js, middleware is treated as a server context where server-only is permitted. Search .nextjs-ref/packages/next/src/build/ for how middleware is layered.

Contributor Guide