cloudflare/vinext

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

已關閉

#1,344 建立於 2026年5月20日

 (1 則留言) (0 個反應) (0 位負責人)TypeScript (383 個分叉)github user discovery
adapter-api-e2ehelp wanted

倉庫指標

星標
 (8,624 顆星)
PR 合併指標
 (平均合併 1天 1小時) (30 天內合併 462 個 PR)

描述

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.

貢獻者指南