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 @@