WindowsmacOSLinux

Where Does Webpack Store Its Filesystem Cache?

Webpack 5 caches builds in node_modules/.cache/webpack. Enabling it, relocating with cacheDirectory and CI sharing rules.

Last updated

Webpack 5 caches to node_modules/.cache/webpack when cache.type is filesystem (the development default). The final path appends cache.name, and invalidation keys off config, lockfiles, Node and webpack versions. Same absolute path matters: CI jobs must run in identical directories for shared caches to hit.

Move it with cache.cacheDirectory (or pin cache.cacheLocation outright) for RAM disks or shared runners. Never commit it: entries embed absolute paths and go stale across machines. Fresh npm ci installs already prune it, which is why clean checkouts build slowly exactly once.

Where Webpack stores this, by platform

Windows
node_modules\.cache\webpack

Default with filesystem caching. Relocate via cacheDirectory for cramped system drives. Absolute-path sensitivity bites hardest with differently-lettered CI drives.

macOS
node_modules/.cache/webpack

Same default. babel-loader keeps its own separate cache beside it when cacheDirectory is on. Delete the webpack folder alone to force a full rebuild.

Linux
node_modules/.cache/webpack

Mirrors macOS. Docker layer caching benefits most here: copy lockfiles and install first so this folder persists across code-only rebuilds.

Frequently asked questions

How do I clear the webpack cache?

Delete node_modules/.cache/webpack (or your custom cacheDirectory) and rebuild. Production mode disables the cache entirely, so prod-only staleness points at output caching or CDN instead.

How do I share the webpack cache in CI?

Persist node_modules/.cache/webpack between jobs keyed on lockfile plus branch, and run every job at the same absolute path. Skip sharing when npm ci runs in the caching job since it prunes the folder.

Notice an outdated path? Let us know.