From 5976a3bed26ce3388996dd2a53ee1d83328257e2 Mon Sep 17 00:00:00 2001 From: Ian Maloney Date: Sat, 21 Feb 2026 17:28:01 +0000 Subject: [PATCH] fix: strip import attributes from dynamic imports --- packages/vite/src/node/plugins/importAnalysis.ts | 2 +- .../import-assertion/__tests__/import-assertion.spec.ts | 4 ++++ playground/import-assertion/index.html | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index c02166958aef13..0a84e49966a5c7 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -520,7 +520,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const isDynamicImport = dynamicIndex > -1 // strip import attributes as we can process them ourselves - if (!isDynamicImport && attributeIndex > -1) { + if (attributeIndex > -1) { str().remove(end + 1, expEnd) } diff --git a/playground/import-assertion/__tests__/import-assertion.spec.ts b/playground/import-assertion/__tests__/import-assertion.spec.ts index 796011926f0e7d..730d888270d820 100644 --- a/playground/import-assertion/__tests__/import-assertion.spec.ts +++ b/playground/import-assertion/__tests__/import-assertion.spec.ts @@ -8,3 +8,7 @@ test('from source code', async () => { test('from dependency', async () => { expect(await page.textContent('.dep'), 'world') }) + +test('dynamic import with attributes', async () => { + expect(await page.textContent('.dynamic'), 'bar') +}) diff --git a/playground/import-assertion/index.html b/playground/import-assertion/index.html index 1135de1ff891e0..768d0fe3df1102 100644 --- a/playground/import-assertion/index.html +++ b/playground/import-assertion/index.html @@ -6,6 +6,8 @@

From source code

From dependency

+

+