From f895eb4ead65412cb07c7a5ea58a418c568c9f55 Mon Sep 17 00:00:00 2001 From: Zeb Date: Sun, 1 Mar 2026 15:17:40 -0500 Subject: [PATCH] fix: include package modules in commonjs transform Previously we only transformed CJS modules if they were part of the part of the project and not if they were in the project's dependencies. Now we will apply CJS to ESM transformations if the vite module id can be resolved to a node module. --- packages/vinext/src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vinext/src/index.ts b/packages/vinext/src/index.ts index 8f0030a8..43ec2eb0 100644 --- a/packages/vinext/src/index.ts +++ b/packages/vinext/src/index.ts @@ -1668,7 +1668,16 @@ hydrate(); tsconfigPaths(), // Transform CJS require()/module.exports to ESM before other plugins // analyze imports (RSC directive scanning, shim resolution, etc.) - commonjs(), + commonjs({ + // vite-plugin-commonjs excludes node_modules by default, but there's + // nothing preventing a dependency from using CJS, so we need to include + // node_modules here. + filter(id) { + if (getPackageName(id) !== null) { + return true + } + }, + }), { name: "vinext:config", enforce: "pre",