[PR #198] [MERGED] feat: add CJS support via vite-plugin-commonjs #382

Closed
opened 2026-05-06 12:39:31 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/198
Author: @zebp
Created: 2/28/2026
Status: Merged
Merged: 2/28/2026
Merged by: @southpolesteve

Base: mainHead: zeb/cjs-support


📝 Commits (4)

  • 6d28583 feat: add CJS support via vite-plugin-commonjs
  • 0f4e129 fix: use buildViteConfig() for Pages Router production builds
  • 06df250 fix: move server-only-violation fixture to isolated directory
  • 2d13350 fix: address review feedback from bonk

📊 Changes

21 files changed (+392 additions, -11 deletions)

View changed files

📝 packages/vinext/package.json (+1 -0)
📝 packages/vinext/src/cli.ts (+7 -11)
📝 packages/vinext/src/index.ts (+4 -0)
📝 pnpm-lock.yaml (+163 -0)
tests/cjs.test.ts (+59 -0)
tests/e2e/app-router/cjs.spec.ts (+28 -0)
tests/e2e/pages-router/cjs.spec.ts (+13 -0)
tests/fixtures/app-basic/app/cjs/basic/page.tsx (+5 -0)
tests/fixtures/app-basic/app/cjs/basic/random.ts (+3 -0)
tests/fixtures/app-basic/app/cjs/server-only/page.tsx (+5 -0)
tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/client-component.tsx (+7 -0)
tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/page.tsx (+10 -0)
tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/server-lib.ts (+5 -0)
tests/fixtures/app-cjs-violation/app/global-error.tsx (+25 -0)
tests/fixtures/app-cjs-violation/app/layout.tsx (+15 -0)
tests/fixtures/app-cjs-violation/app/page.tsx (+3 -0)
tests/fixtures/app-cjs-violation/package.json (+13 -0)
tests/fixtures/app-cjs-violation/tsconfig.json (+12 -0)
tests/fixtures/app-cjs-violation/vite.config.ts (+6 -0)
tests/fixtures/pages-basic/pages/cjs/basic.tsx (+5 -0)

...and 1 more files

📄 Description

Add vite-plugin-commonjs to handle require() and module.exports in both App Router and Pages Router. This enables CJS interop in server components and pages, including CJS require('server-only') boundary enforcement by @vitejs/plugin-rsc.

  • Add vite-plugin-commonjs as a dependency and register it in the plugin array
  • Add App Router fixtures: CJS basic, CJS server-only, CJS server-only violation (client component importing server-only module)
  • Add Pages Router fixture: CJS basic (require/module.exports)
  • Add integration tests for both routers (cjs.test.ts)
  • Add App Router e2e tests for CJS rendering and server-only boundary enforcement (tests/e2e/app-router/cjs.spec.ts)
  • Add Pages Router e2e test for CJS rendering (tests/e2e/pages-router/cjs.spec.ts)

Fixes #164


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/198 **Author:** [@zebp](https://github.com/zebp) **Created:** 2/28/2026 **Status:** ✅ Merged **Merged:** 2/28/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `zeb/cjs-support` --- ### 📝 Commits (4) - [`6d28583`](https://github.com/cloudflare/vinext/commit/6d28583cd105c2fc118f97e63c2929c7d23fb356) feat: add CJS support via vite-plugin-commonjs - [`0f4e129`](https://github.com/cloudflare/vinext/commit/0f4e12951d6bb9ea26540f8fd7a7affbe79973d1) fix: use buildViteConfig() for Pages Router production builds - [`06df250`](https://github.com/cloudflare/vinext/commit/06df250a68c02dd7a063d95f8cf9a52d6ba75fae) fix: move server-only-violation fixture to isolated directory - [`2d13350`](https://github.com/cloudflare/vinext/commit/2d1335038886a00d04bd6bd0886b98bfca145d6e) fix: address review feedback from bonk ### 📊 Changes **21 files changed** (+392 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/package.json` (+1 -0) 📝 `packages/vinext/src/cli.ts` (+7 -11) 📝 `packages/vinext/src/index.ts` (+4 -0) 📝 `pnpm-lock.yaml` (+163 -0) ➕ `tests/cjs.test.ts` (+59 -0) ➕ `tests/e2e/app-router/cjs.spec.ts` (+28 -0) ➕ `tests/e2e/pages-router/cjs.spec.ts` (+13 -0) ➕ `tests/fixtures/app-basic/app/cjs/basic/page.tsx` (+5 -0) ➕ `tests/fixtures/app-basic/app/cjs/basic/random.ts` (+3 -0) ➕ `tests/fixtures/app-basic/app/cjs/server-only/page.tsx` (+5 -0) ➕ `tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/client-component.tsx` (+7 -0) ➕ `tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/page.tsx` (+10 -0) ➕ `tests/fixtures/app-cjs-violation/app/cjs/server-only-violation/server-lib.ts` (+5 -0) ➕ `tests/fixtures/app-cjs-violation/app/global-error.tsx` (+25 -0) ➕ `tests/fixtures/app-cjs-violation/app/layout.tsx` (+15 -0) ➕ `tests/fixtures/app-cjs-violation/app/page.tsx` (+3 -0) ➕ `tests/fixtures/app-cjs-violation/package.json` (+13 -0) ➕ `tests/fixtures/app-cjs-violation/tsconfig.json` (+12 -0) ➕ `tests/fixtures/app-cjs-violation/vite.config.ts` (+6 -0) ➕ `tests/fixtures/pages-basic/pages/cjs/basic.tsx` (+5 -0) _...and 1 more files_ </details> ### 📄 Description Add vite-plugin-commonjs to handle require() and module.exports in both App Router and Pages Router. This enables CJS interop in server components and pages, including CJS require('server-only') boundary enforcement by @vitejs/plugin-rsc. - Add vite-plugin-commonjs as a dependency and register it in the plugin array - Add App Router fixtures: CJS basic, CJS server-only, CJS server-only violation (client component importing server-only module) - Add Pages Router fixture: CJS basic (require/module.exports) - Add integration tests for both routers (cjs.test.ts) - Add App Router e2e tests for CJS rendering and server-only boundary enforcement (tests/e2e/app-router/cjs.spec.ts) - Add Pages Router e2e test for CJS rendering (tests/e2e/pages-router/cjs.spec.ts) Fixes #164 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:31 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#382
No description provided.