-
Notifications
You must be signed in to change notification settings - Fork 271
Open
Description
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
- Create an App Router project with
app/page.tsx:
import dep from "cjs-node-package";
export default function Page() {
return <div>{dep.value}</div>;
}- Add a CommonJS-only package in
node_modules/cjs-node-package/index.js:
module.exports = { value: "from-cjs-package" };- Run
vinext devand request/.
Current result
Dev returns 500 and the response includes a Vite/RSC parse error:
A module cannot have multiple default exportsIn 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()inpackages/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-rscplus vinext'srsc/ssrenvironments configured inpackages/vinext/src/index.ts. - Those environments currently force
noExternal: true(except for explicit externals), so rawnode_modulespackages 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/ssrenvironments in dev, or transformed into valid ESM/CommonJS-compatible modules before@vitejs/plugin-rscsees them. - Keep the existing reasons for
noExternal: truein mind: CSS/assets innode_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 SSR dev server fails with "module is not defined" for CJS dependencies (void-elements, highlight.js, etc.) #585 after PR fix: support CommonJS node_modules in Pages Router dev #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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels