diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 0baba266958434..70d364900d03e9 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -218,6 +218,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { if (imports.length) { const s = new MagicString(code) + const analyzed: Set = new Set() for (let index = 0; index < imports.length; index++) { const { s: start, e: end, d: dynamicIndex } = imports[index] // if dynamic import polyfill is used, rewrite the import to @@ -234,6 +235,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // literal import - trace direct imports and add to deps const addDeps = (filename: string) => { if (filename === ownerFilename) return + if (analyzed.has(filename)) return + analyzed.add(filename) const chunk = bundle[filename] as OutputChunk | undefined if (chunk) { deps.add(config.base + chunk.fileName)