From 4a42cae8db04ebd5b526fe45b03a51a24a0e5863 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 20 Jan 2026 17:26:42 +0900 Subject: [PATCH] fix(optimizer): skip `rolldownCjsExternalPlugin` for `platform: neutral` --- packages/vite/src/node/optimizer/rolldownDepPlugin.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/rolldownDepPlugin.ts b/packages/vite/src/node/optimizer/rolldownDepPlugin.ts index 9aad39c9939898..48b2f4f00f6d8a 100644 --- a/packages/vite/src/node/optimizer/rolldownDepPlugin.ts +++ b/packages/vite/src/node/optimizer/rolldownDepPlugin.ts @@ -315,10 +315,14 @@ export function rolldownCjsExternalPlugin( if (platform === 'node') { return undefined } + // Skip this plugin for `platform: 'neutral'` as we are not sure whether `require` is available + if (platform === 'neutral') { + return undefined + } // Apply this plugin for `platform: 'browser'` as `require` is not available in browser and // converting to `import` would be necessary to make the code work - platform satisfies 'browser' | 'neutral' + platform satisfies 'browser' const filter = new RegExp(externals.map(matchesEntireLine).join('|'))