Dependency optimization causes duplication when applied during the build #11463
Labels
feat: deps optimizer
Esbuild Dependencies Optimization
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
The bug was quite hard to track down and reproduce as the build time optimizations depend on the size and structure of the project. I managed to reproduce it in both Vite 3 and Vite 4.
The issue might be related to #9171, but it seems to be slightly different, as it doesn't report any duplicated modules differing by a query when using the hook from the mentioned issue.
In the attached reproduction,
chart.js
library is imported in two places. It is imported directly into the project, and by thechartjs-plugin-datalabels
plugin. There is also a rollup plugin added in order to slow down the build process, and leave some time for the build time optimization mechanism.The first time the build is started, there are
✨ new dependencies optimized
and✨ optimized dependencies changed. reloading
messages. Output js file contains ~27k lines of code, whereas the second time the build is triggered, it results in ~15k lines.The output contains, among other things, a duplicated
ArcElement
class, coming from thechart.js
library. It is the direct cause of the issue, visible in the browser console (and on the screen, as the chart is not being rendered properly).Reproduction
https://github.com/mciesin/vite-build-issue
Steps to reproduce
npm install
,npm build
andnpm preview
.npm build
andnpm preview
..vite
cache.System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: