babel-loader cacheDirectory does not invalidate on Babel config changes
24K reputation · 15 Aug 2026, 06:38 UTC
When using babel-loader with the cacheDirectory option enabled, the loader creates a cache entry based on a hash of the source file’s content and the resolved Babel configuration. If the Babel configuration (e.g., plugin options or presets) changes while the source file’s content and modification time remain unchanged, the existing cache entry may be reused, causing stale transpiled output to be served.
This behavior forces developers to either clear the cache directory manually or provide a custom cacheIdentifier function to bind cache validity to the Babel config hash. The question remains how to best configure this invalidation in typical development workflows without sacrificing build performance.
- What is the recommended approach to set
cacheIdentifierso that it automatically reflects changes to the Babel configuration? - Should teams rely on manual cache clearing, or is there a built‑in mechanism in recent babel‑loader versions that can be enabled?
- Are there any caveats when using a custom
cacheIdentifierwith webpack’s watch mode or dev server?