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.

Webpack 5 - Memory Leak

See original GitHub issue

Bug report

What is the current behavior?

When I make a change in my web app and Webpack compiles, memory usage seems to increase. If I keep making changes and Webpack keeps re-compiling, memory usage will continue to climb. In a large project I work in, it takes about 10 compilations until Webpack crashes with a “Allocation failed - JavaScript heap out of memory” exception.

If the current behavior is a bug, please provide the steps to reproduce.

Please see the minimal repo I created to reproduce the issue: https://github.com/smparsons/webpack-memory-leak-issue. The instructions to reproduce are on the README.

What is the expected behavior?

I would expect some kind of garbage collection to happen in between compilations.

Other relevant information: webpack version: 5.0.0-beta.15 Node.js version: 11.10.1 Operating System: macOS Catalina Version 10.15 Additional tools:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
sokracommented, Apr 28, 2020

Do not use any kind of hash in the filename during development when using webpack-dev-middleware. Each compilation will create a new file as filename changes. Just like files will pile up on disk, they will pile up in memory as the webpack-dev-middleware stores output files in memory.

0reactions
joshxyzhimselfcommented, Oct 28, 2020

This one does the trick, right?

{
    output: {
      filename: mode === 'production' ? '[chunkhash].js' : '[name].js',
      chunkFilename: mode === 'production' ? '[chunkhash].js' : '[name].js',
    },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 memory leak in watch mode · Issue #12771 - GitHub
In a large project I work in, it takes about 10 compilations until Webpack crashes with a "Allocation failed - JavaScript heap out...
Read more >
Webpack: How to fix "Heap out of memory - m4x
The primary reason why Webpack would fail is when we have too many files that when they are in memory the whole build...
Read more >
ES6 DYNAMIC IMPORT AND WEBPACK MEMORY LEAKS
A memory leak! It's been a while since I saw one of those. After 10 minutes of chewing on the code, Webpack decided...
Read more >
Identifying memory leak in webpack build - Stack Overflow
When I run my development server, and some times even the production server the build crashes sporadically saying the javascript heap is out...
Read more >
Understanding memory leaks in Node.js apps - LogRocket Blog
The above example is likely to cause a memory leak because the variable requests , which holds a new instance of the Map...
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