Force Vite to Pre-bundle Stubborn CommonJS Dependencies
Use vite.config.ts optimizeDeps.include to force pre-bundling of CommonJS packages and fix missing exports in Vite dev.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Use vite.config.ts optimizeDeps.include to force pre-bundling of CommonJS packages and fix missing exports in Vite dev.
Vite’s dependency pre‑bundling can make or break a monorepo dev workflow. Learn when to include or exclude workspace packages, how to fine‑tune <code>optimizeDeps</code>, and avoid common pitfalls with a concrete example and practical checklist.
Vite pre-bundles node_modules with esbuild in dev, so a stale optimized bundle is usually a cache and discovery problem — not a broken install.
Vite pre-bundles your dependencies with esbuild at dev-server startup, turning hundreds of module requests into one per package. Here's how it works, how to verify it, and when to tune optimizeDeps.
The goal is to keep the number of JavaScript requests the browser makes during development low while avoiding an overly large pre‑bundled chunk that hurts initial load time. Vite achieves this by pre‑bundling dependencies with esbuild, but the decision of which packages to bundle depends on Vite’s heuristic for detecting side‑effects. This heuristic is docum
Goal Diagnose a deployment failure that appears to stem from Vite’s pre‑bundling of dependencies. The project’s vite.config.js lists a specific module in both optimizeDeps.include and optimizeDeps.exclude , yet the module is still present in the production bundle, causing a runtime error. Constraints The configuration API is unchanged between Vite 4.x and 5.
When configuring Vite's dependency pre‑bundling, I want to use a glob pattern such as lodash-* in optimizeDeps.include to automatically pre‑bundle all lodash submodules without listing each one individually. However, the documentation states that optimizeDeps.include accepts only exact package name strings and does not interpret glob patterns, and it does no