[GH-ISSUE #666] App Router dev still fails on raw CommonJS packages from node_modules #142

Open
opened 2026-05-06 12:37:36 +02:00 by BreizhHardware · 1 comment

Originally created by @southpolesteve on GitHub (Mar 23, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/666

Background

PR #665 fixes Pages Router dev for raw CommonJS packages from node_modules by making the direct dev module runner CommonJS-aware. App Router still fails in a separate pipeline.

Reproduction

  1. Create an App Router project with app/page.tsx:
import dep from "cjs-node-package";

export default function Page() {
  return <div>{dep.value}</div>;
}
  1. Add a CommonJS-only package in node_modules/cjs-node-package/index.js:
module.exports = { value: "from-cjs-package" };
  1. Run vinext dev and request /.

Current result

Dev returns 500 and the response includes a Vite/RSC parse error:

A module cannot have multiple default exports

In my repro, that surfaced from the generated/prebundled @vitejs_plugin-rsc_vendor_react-server-dom_server__edge.js path rather than from the package source directly.

Why the Pages Router fix does not apply

  • Pages Router uses createDirectRunner() in packages/vinext/src/server/dev-module-runner.ts.
  • App Router does not use that runner for request-time module loading.
  • App Router goes through @vitejs/plugin-rsc plus vinext's rsc/ssr environments configured in packages/vinext/src/index.ts.
  • Those environments currently force noExternal: true (except for explicit externals), so raw node_modules packages are still pushed through Vite/plugin-rsc transforms.

What a fix likely needs

  • Add a focused App Router regression test for a raw CommonJS package from node_modules.
  • Decide whether these packages should be externalized from the App Router rsc/ssr environments in dev, or transformed into valid ESM/CommonJS-compatible modules before @vitejs/plugin-rsc sees them.
  • Keep the existing reasons for noExternal: true in mind: CSS/assets in node_modules, RSC bundling, and React Server condition handling.
  • Verify parity against Next.js App Router for CommonJS-only dependencies.

Constraints / notes

  • This is a different problem from #585 after PR #665 lands.
  • A direct-runner evaluator fallback is probably not enough here because the failing path is inside the App Router RSC pipeline, not the Pages Router direct-runner path.
Originally created by @southpolesteve on GitHub (Mar 23, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/666 ## Background PR #665 fixes Pages Router dev for raw CommonJS packages from `node_modules` by making the direct dev module runner CommonJS-aware. App Router still fails in a separate pipeline. ## Reproduction 1. Create an App Router project with `app/page.tsx`: ```tsx import dep from "cjs-node-package"; export default function Page() { return <div>{dep.value}</div>; } ``` 2. Add a CommonJS-only package in `node_modules/cjs-node-package/index.js`: ```js module.exports = { value: "from-cjs-package" }; ``` 3. Run `vinext dev` and request `/`. ## Current result Dev returns `500` and the response includes a Vite/RSC parse error: ```txt A module cannot have multiple default exports ``` In my repro, that surfaced from the generated/prebundled `@vitejs_plugin-rsc_vendor_react-server-dom_server__edge.js` path rather than from the package source directly. ## Why the Pages Router fix does not apply - Pages Router uses `createDirectRunner()` in `packages/vinext/src/server/dev-module-runner.ts`. - App Router does not use that runner for request-time module loading. - App Router goes through `@vitejs/plugin-rsc` plus vinext's `rsc`/`ssr` environments configured in `packages/vinext/src/index.ts`. - Those environments currently force `noExternal: true` (except for explicit externals), so raw `node_modules` packages are still pushed through Vite/plugin-rsc transforms. ## What a fix likely needs - Add a focused App Router regression test for a raw CommonJS package from `node_modules`. - Decide whether these packages should be externalized from the App Router `rsc`/`ssr` environments in dev, or transformed into valid ESM/CommonJS-compatible modules before `@vitejs/plugin-rsc` sees them. - Keep the existing reasons for `noExternal: true` in mind: CSS/assets in `node_modules`, RSC bundling, and React Server condition handling. - Verify parity against Next.js App Router for CommonJS-only dependencies. ## Constraints / notes - This is a different problem from #585 after PR #665 lands. - A direct-runner evaluator fallback is probably not enough here because the failing path is inside the App Router RSC pipeline, not the Pages Router direct-runner path.
Author
Owner

@dandanthedev commented on GitHub (Mar 30, 2026):

+1, im running into this aswell

<!-- gh-comment-id:4155342691 --> @dandanthedev commented on GitHub (Mar 30, 2026): +1, im running into this aswell
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#142
No description provided.