[PR #665] fix: support CommonJS node_modules in Pages Router dev #754

Open
opened 2026-05-06 13:09:56 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/665
Author: @southpolesteve
Created: 3/23/2026
Status: 🔄 Open

Base: mainHead: codex/pages-router-cjs-node-modules


📝 Commits (1)

  • ff56b46 fix: support CommonJS node_modules in Pages Router dev

📊 Changes

2 files changed (+215 additions, -3 deletions)

View changed files

📝 packages/vinext/src/server/dev-module-runner.ts (+131 -2)
📝 tests/cjs.test.ts (+84 -1)

📄 Description

Summary

  • add a CommonJS-aware evaluator to the direct dev module runner used by Pages Router requests
  • limit that compatibility path to raw node_modules and .cjs modules, while preserving Vite's normal ESM evaluator everywhere else
  • add a regression test covering a Pages Router page that imports a nested CommonJS package from node_modules

This matches the Pages Router bug reported in #585. In Next.js, Pages Router dependencies are externalized by default unless bundlePagesRouterDependencies is enabled, so raw CommonJS packages should not crash dev SSR with module is not defined.

Fixes #585.

Verification

  • vp test run tests/cjs.test.ts tests/node-modules-css.test.ts
  • vp check packages/vinext/src/server/dev-module-runner.ts tests/cjs.test.ts

Notes

  • This change is intentionally scoped to the Pages Router direct-runner path.
  • App Router still goes through the @vitejs/plugin-rsc pipeline and needs separate work tracked in #666.

🔄 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/665 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/23/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/pages-router-cjs-node-modules` --- ### 📝 Commits (1) - [`ff56b46`](https://github.com/cloudflare/vinext/commit/ff56b46c09b946ed8a1d133be5b3dfb206343eb6) fix: support CommonJS node_modules in Pages Router dev ### 📊 Changes **2 files changed** (+215 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/dev-module-runner.ts` (+131 -2) 📝 `tests/cjs.test.ts` (+84 -1) </details> ### 📄 Description ## Summary - add a CommonJS-aware evaluator to the direct dev module runner used by Pages Router requests - limit that compatibility path to raw `node_modules` and `.cjs` modules, while preserving Vite's normal ESM evaluator everywhere else - add a regression test covering a Pages Router page that imports a nested CommonJS package from `node_modules` This matches the Pages Router bug reported in #585. In Next.js, Pages Router dependencies are externalized by default unless `bundlePagesRouterDependencies` is enabled, so raw CommonJS packages should not crash dev SSR with `module is not defined`. Fixes #585. ## Verification - `vp test run tests/cjs.test.ts tests/node-modules-css.test.ts` - `vp check packages/vinext/src/server/dev-module-runner.ts tests/cjs.test.ts` ## Notes - This change is intentionally scoped to the Pages Router direct-runner path. - App Router still goes through the `@vitejs/plugin-rsc` pipeline and needs separate work tracked in #666. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#754
No description provided.