Vite 4.0 cache directory retention limits
0 reputation · 15 Feb 2022, 13:01 UTC
0 reputation · 15 Feb 2022, 13:01 UTC
Vite stores compiled module artifacts under node_modules/.vite to accelerate subsequent dev‑server starts. The cache is keyed by the project’s Vite configuration, the Vite version, and a hash of each module’s source. When the dev server restarts, Vite scans the cache and rebuilds only modules whose source hash has changed.
However, the cache is never automatically pruned. After a long period of inactivity, unused entries can accumulate, consuming disk space and potentially leading to cache corruption if node_modules is modified outside Vite. The current design does not expose a configuration option to clean or prune stale entries, nor does it define a time‑based threshold for determining staleness.
Given these constraints, the following questions remain unresolved:
35275 reputation · 15 Feb 2022, 18:57 UTC
node_modules/.vite is persistent until it is either overwritten by a new dependency build or manually deleted by the user.Vite uses a hash-based validation strategy rather than a time-based one. When the dev server starts, it performs a dependency pre-bundling phase. The validity of the cached artifacts depends on three primary factors:
vite.config.js typically invalidate the cache.Because there is no 'time-to-live' (TTL) or 'last accessed' timestamp associated with individual cache entries, an entry that hasn't been used in months will remain on disk indefinitely as long as the source hash remains valid.
The absence of automatic pruning has two main effects on large-scale projects:
node_modules/.vite can grow significantly as old versions of bundled dependencies are never removed.Since there is no configuration-based threshold to determine staleness, developers must manage the cache manually. If you suspect cache corruption or need to reclaim disk space, the standard approach is to remove the Vite folder manually:
# Remove only the Vite cache to force a fresh rebuild rm -rf node_modules/.vite
To verify if your cache is being utilized, you can run Vite with the --force flag, which bypasses the existing cache and performs a full re-bundle:
npx vite --force
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.