SourceMapDevTool plugin leaks memory in watch mode
See original GitHub issueBug report
What is the current behavior?
If I use devtool:"cheap-module-source-map"
, assets with [contenthash]
filenames, and webpack in watch mode, it appears to store sourcemaps in webpack’s in-memory cache with identifiers including a hash key. On a large app these source maps can be pretty big and eventually cause webpack to run out of memory.
I added a logpoint to webpack’s Cache.store method to print the identifier
. Every time a file changed it showed something like :
store ResolverCachePlugin|normal|dependencyType=|esm|path=|/Users/jon/Developer/webpack-leak|request=|./src/index.js
store Compilation/modules|/Users/jon/Developer/webpack-leak/src/index.js
store FlagDependencyExportsPlugin|/Users/jon/Developer/webpack-leak/src/index.js
store Compilation/codeGeneration|/Users/jon/Developer/webpack-leak/src/index.js|main
store Compilation/assets|chunkmain
store SourceMapDevToolPlugin|main.45881470b72af5d10497.js
Inspecting the cache with Chrome’s debugger showed that it had single entries for, eg, Compilation/assets|chunkmain
but multiple entries for SourceMapDevToolPlugin|main.<hash>.js
If the current behavior is a bug, please provide the steps to reproduce.
Use devtool:"cheap-module-source-map"
, output.filename:"[contenthash].js"
and run webpack --watch
.
Make a series of changes to files on disk
Watch memory usage continue to grow.
I added a reproduction repository here : https://github.com/jdelStrother/webpack-leak/blob/main/webpack.config.js - with such a small codebase it’s not going to show the memory growth very well, but hopefully you can see the Cache.store function receiving identifiers containing contenthash keys.
What is the expected behavior?
Webpack’s cache doesn’t keep growing. I assume SourceMapDevToolPlugin should be passing contenthash-less identifiers to the cache.
Other relevant information: webpack version: 5.27.1 Node.js version: 14.16 Operating System: MacOS Big Sur Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top GitHub Comments
#12990 allows you to set
cache: { type: "memory", maxGenerations: 5 }
which will GC memory cache entries when they are unused for a while (between 5 and ~10 rebuilds with this setting). This should help with this issue. And you needoutput.clean
to get rid of the assets in the memory filesystem.Close in favor https://github.com/webpack/webpack/pull/12990