question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SourceMapDevTool plugin leaks memory in watch mode

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Apr 1, 2021

#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 need output.clean to get rid of the assets in the memory filesystem.

0reactions
alexander-akaitcommented, Jun 1, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

azu on Twitter: "見てる: "SourceMapDevTool plugin leaks ...
見てる: "SourceMapDevTool plugin leaks memory in watch mode · Issue #12947 ... and webpack in watch mode, it appears to store sourcemaps.
Read more >
SourceMapDevToolPlugin - webpack
This plugin enables more fine grained control of source map generation. It is also enabled automatically by certain settings of the devtool configuration ......
Read more >
Easily detect memory leak source using chrome dev tools ...
Detecting a memory leak is not always easy. ... is a great tool with a visualisation that helps you track down memory leaks...
Read more >
Webpack: How to fix "Heap out of memory - m4x
Memory leaks are pretty often a big deal in Webpack and plugins. Try to be up to date with the versions but not...
Read more >
2021-04-06のJS: TypeScript 4.3 Beta、hls.js v1.0.0 ... - JSer.info
また、Controls addonが改善され、JSON editorやcolor pickerなどの機能が ... SourceMapDevTool plugin leaks memory in watch mode · Issue #12947 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found