webpack: Process out of memory - Webpack
After a couple of builds running in a Watch, Webpack crashes due to being out of memory.
<--- Last few GCs --->
9223585 ms: Scavenge 1390.0 (1454.7) -> 1390.0 (1454.7) MB, 9.0 / 0 ms (+ 0.7 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
9224727 ms: Mark-sweep 1390.0 (1454.7) -> 1388.3 (1452.7) MB, 1142.7 / 0 ms (+ 9.8 ms in 89 steps since start of marking, biggest step 2.5 ms) [last resort gc].
9225694 ms: Mark-sweep 1388.3 (1452.7) -> 1388.8 (1454.7) MB, 966.6 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x35903c44a49 <JS Object>
1: walkFunctionDeclaration [<PROJECT_DIR>/node_modules/webpack/lib/Parser.js:~443] [pc=0xa07a14ec8ee] (this=0x59f67991119 <a Parser with map 0x71f2d115d49>,statement=0x3507a80af661 <a Node with map 0x71f2d1157c9>)
2: walkStatement [<PROJECT_DIR>/node_modules/webpack/lib/Parser.js:~348] [pc=0xa07a06dfc10] (this=0x59f6799111...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Abort trap: 6
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 229
- Comments: 124 (14 by maintainers)
Links to this issue
Commits related to this issue
- Fix memory problems with webpack-dev-server in dev mode (#2433) Before this webpack was using hashes in filenames for the generated files which are stored in memory. That meant on every change new f... — committed to Graylog2/graylog2-server by bernd 8 years ago
- Fix memory problems with webpack-dev-server in dev mode (#2433) Before this webpack was using hashes in filenames for the generated files which are stored in memory. That meant on every change new fi... — committed to Graylog2/graylog2-server by bernd 8 years ago
- chore(build): remove sourcemap generation to get around memory leak in webpack https://github.com/webpack/webpack/issues/1914 is the issue we were seeing. — committed to rgbkrk/nteract by ivanov 8 years ago
- Change the extension path to not expand to sub-directories to stop OOM error. After upgrading to 2.0, I was consistently running out of RAM when trying to run webpack. After some digging, I came acr... — committed to robdimarco/webpacker by deleted user 7 years ago
- Do not use hash to prevent dev server crash see https://github.com/webpack/webpack/issues/1914 Signed-off-by: Andy Shu <andyshuhsin@gmail.com> — committed to wikimigrate/wikimigrate by blaesus 7 years ago
- Generate sourcemaps in production Resolves instructure/canvas-lms#1101 In production, generate separate sourcemap files so that bundles appear split into their original, un-obfuscated source files i... — committed to sfu/canvas-lms by grahamb 7 years ago
- Generate JavaScript sourcemaps in production Resolves instructure/canvas-lms#1101 In production, generate separate sourcemap files so that bundles appear split into their original, un-obfuscated sou... — committed to sfu/canvas-lms by grahamb 7 years ago
- Generate JavaScript sourcemaps in production Resolves instructure/canvas-lms#1101 In production, generate separate sourcemap files so that bundles appear split into their original, un-obfuscated sou... — committed to sfu/canvas-lms by grahamb 7 years ago
- Generate JavaScript sourcemaps in production Resolves instructure/canvas-lms#1101 In production, generate separate sourcemap files so that bundles appear split into their original, un-obfuscated sou... — committed to sfu/canvas-lms by grahamb 7 years ago
- Generate JavaScript sourcemaps in production Resolves instructure/canvas-lms#1101 In production, generate separate sourcemap files so that bundles appear split into their original, un-obfuscated sou... — committed to instructure/canvas-lms by grahamb 7 years ago
- chore: fix Webpack CALL_AND_RETRY_LAST allocation error See: https://github.com/webpack/webpack/issues/1914 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com> — committed to balena-io/etcher by jviotti 6 years ago
- ORG-550: Remove bundle hash in dev to reduce memory leak https://github.com/webpack/webpack/issues/1914 — committed to c7s/react-boilerplate by fenok 5 years ago
- docs: maybe fix memory leak [chunkhash] might cause gc problems: https://github.com/webpack/webpack/issues/1914 see also https://github.com/webpack/webpack/issues/6929 — committed to vuetifyjs/vuetify by KaelWD 5 years ago
- Bump node build version When trying to build the Docker image, I kept receiving an out-of-memory error from Webpack. This issue is apparently explained at https://github.com/webpack/webpack/issues/19... — committed to mattcen/riot-web by mattcen 4 years ago
- Bump node build version When trying to build the Docker image, I kept receiving an out-of-memory error from Webpack. This issue is apparently explained at https://github.com/webpack/webpack/issues/19... — committed to mattcen/riot-web by mattcen 4 years ago
Did someone resolved this problem?
Another data point here; I have filename hashes disabled and my build isn’t terribly large (it uses Angular 2, but few other dependencies), but after about an hour of dev work the watch dies with
Abort trap: 6
.I’ve temporarily increased the memory limit, which gives me a lot more time, but I’d rather not be consuming gigabytes just to run a watch command.
FYI if anyone is curious about upping the memory limit, I did it like so in my package.json (obviously the additional flags are dependent on your needs):
Don’t use hashes when watching. i. e.
[chunkhash]
causes all assets to be stored.@buildbreakdo A better option is to do this:
(It uses the
cross-env
package.)The nice thing about using
NODE_OPTIONS
is that it will affect everything, including any sub-processes that Webpack might spawn.(It’s useful for non-Webpack things as well: we’re using it for TypeDoc, which consumes a lot of RAM.)
this is happening on webpack 4 as well
I had this problem with the version 10… of node but, when I upgraded to the v12.4.0 the error gone.
I got this in
production
mode, but notdevelopment
🤷♂️I’m getting the
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
basically after every 5-10 rebuilds in dev mode using --watch. Is there any way to get around this in webpack 1.14.0?jup.
You can navigate to http://localhost:8080/webpack-dev-server to see a list of all files in memory.
Cause is usually processing of a large file that causes V8 to run out of RAM. By default V8 is only allocated 1400 MB of RAM. If you are seeing this error, it is likely that you need to increase this number.
V8 flags are set in a package.json script by declaring the flag between the call to
node
and./yourScriptName
.Do not do this in your package.json scripts section, this passes the flag to webpack which is the wrong thing to do:
Do this:
This is equivalent to:
or
Derived this answer from these two issues, credits to the angular/node folks: https://github.com/nodejs/node/issues/7937 https://github.com/angular/angular-cli/issues/1652
I can never find the answer to my question when looking at github threads like this. I see merges, closes, tags, etc but no body really says what causes the issue and how to fix it. sigh. Lets try my luck in stack overflow again.
Not sure if there is anyone else here using webpacker, but the problem for me was that in
config/webpack/shared.js
they changed this:to this:
Which explains why it may be traversing down directories and loading files that are never actually used by the dependency graph. Dropping the
**/
fixed the out of memory issue for me.Same issue for a very small project
export NODE_OPTIONS=--max_old_space_size=4096
Works for me.
Three hours? I think the problem is just that you need more patience.
+1…
remove max_old_space_size
just add to ts-loader
This solution did resolve the problem in my project.
Same problem. Our production builds have recently started failing too. Typescript + React. We’ve increased memory for our node processes to no avail. Any advice or what version to roll back to?
Having the same problem running
webpack
viawebpack-stream
ingulp
. I usegulp.watch
to rerun on code changes, which then just runsI’d have thought this would run webpack from scratch each time, but after 5 or so builds I get the out of memory error and have to rerun my gulp file.
Still happening on webpack 4.17.1
+1. Is someone able to give a definitive solution outside of setting
max_old_space_size
?any solution to this ?
Having the same issue as @thunderkid here. Any update?
We have the exact same memory leak problem after using webpack -w on MacOS X. Can you please suggest what is a the best way to fix / workaround this issue. The ngOfficeUIFabric seems to deal with a different problem.
Thanks, Deepak
Memory leak found https://github.com/suguru03/neo-async/pull/83
I had this issue a year ago (see above in July 2017).
Some things I’ve done to our project since then - this issue has gone away entirely, confirmed on Mac, Linux, and Windows 10 dev workstations:
webpack
v4+ (version 3 was causing some issues for me)webpack-dev-middleware
v3+watchOptions: { poll: false }, stats: 'minimal' }
poll: false
is important if you are using Docker 🐳 (I’m also using an alpine image for those who carenode:8.11.4-alpine
), it solves some performance hiccupseslint
plugin, make sure it is v4+, especially if its part of webpack config, ensure any non-source files are ignoredAlso still using
react-transform-hmr
v1.0.4, no issues with this version.Another final note: If you use WebStorm, I would disable “safe write” as it usually causes performance issues, most often when your hard drive is symlinked into a Docker container. Similar settings may exist in other IDEs.
For what it’s worth, here is a snippet of the webpack config:
Got an issue resolved on one of the machine using below:
Try this out: In "ProjectDirectory\node_modules\.bin" modify webpack.cmd to:
@IF EXIST “%~dp0\node.exe” ( "%~dp0\node.exe --max_old_space_size=4096 " “%~dp0..\webpack\bin\webpack.js” %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node --max_old_space_size=4096 “%~dp0..\webpack\bin\webpack.js” %* )
and try to build. Basically, its going to use –max_old_space_size=4096 with node webpack build.
See if that helps.
Same issue here. Running webpack dev server takes up ~3-3.5gb of ram on my machine
Not sure if this is going to help anyone but we had a problem after updating to webpack 4 with the out of memory error. The build itself would often get stuck or become very slow. What very unexpectedly helped us was removing the
BundleAnalyzerPlugin
.I fixed it disabling ModuleConcatenationPlugin!
Seems related to Webpack 3 upgrade for me as well
On Node v8.1.2 with upgrade from
webpack@2.4.1
=>webpack@3.0.0
caused much slowdown and theCALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
error.Upon doing:
rm -rf node_modules
and thennpm install
withwebpack@2.4.1
, the problem goes away, and compiling/build times are dramatically reduced.We faced a similar problem with webpack-dev-server. Using a more aggressive policy for CommonsChunk plugin reduced memory usage from 1.8GB to 1.1GB,
minChunks
was set to 3 to include most of the shared code:Is there a way to disable the usage of memory of FS and to use regular file system?
Having had this problem today, I updated this line:
To:
And all was suddenly OK…
Our solution was to shorten project folder’s name from about 25 down to 4 symbols. It works. So far… webpack 3.4.1
we are a big team 👍
After every 5-6 build on dev mode including
--hot --inline --progress --colors --port 2000
, i got thisFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
webpack
v3.1.0
webpack-dev-server
v2.5.1
Just upgraded to webpack 3.0 and experiencing leaks as well:
The problem for me was a memory leak in postcss-loader v1.3.x, no more crashes so far after an upgrade to v.2.0.5
+1 same issue here deploying to heroku
I’m experiencing the same issue here. From what can I tell, it seems that Webpack is loading up files in the project directory even when they are technically “unreachable” from the dependency graph, starting from the given entry points.
I’m trying to integrate Webpack into an existing project with a large existing Javascript code (written as Typescript). This is where Webpack throws OOM errors.
So as an experiment, I try to make a minimal Webpack test example, as described in this gist. This compiles fine, so far so good.
But, when I copy the
src
directory of the large project into my minimal example, Webpack then throws OOM errors. Note that I just copied thesrc
directory; none of the files in the given gist example were changed.FWIW, I ran Webpack with
strace
and I get traces likeI’m not sure if this is normal behavior or not but it is looking for
node_modules
way beyond where it is supposed to look.strace
also makes me sure that Webpack is indeed digging into the unreferencedsrc
directory. I get traces like,Same issue has just started for me. Has there been any update on this?
@sokra In the documentation for css-loader it says to use hash for easier debugging wrt css modules. Does that have the same problem?
We’ve also started to see this problem in dev (out of memory), but our only hash in dev mode is the css one.
EDIT: Of course it uses hash by default, so I’m guessing it’s not a problem.
Just adding my experience here. I did have issues with compilation on the
t1.micro
size but I did not on thet2.small
.@buildbreakdo what if build works great, and then after some hot module reloads, it keeps using more memory and then crashes
is this a bug on hot module reload?
What pushes a build over the 1400 MB ram allocated by node will be different for each project. There is no webpack bug here. However, there could be a bug in your build configuration (like compiling node_modules).
Or maybe, just maybe, the project is just that big and the build process requires more RAM than Nodes default 1400 MB. If you would like to increase the RAM allocated to Node see instructions above here: https://github.com/webpack/webpack/issues/1914#issuecomment-392660230
Same probleme here. I use Webpack (Dev Server) with Pug templates and HTMLWebpackPlugin.
The problem is the RegEx, when it catch the files, it doesn’t filter well. If I build, removing the node_modules (from task_modules/primer_modulo/node_modules), it works well.
Same issue
Command used
webpack --watch --progress
Webpack
v3.2.0
Node
v5.12.0
I have same issue, though I am using ionic app scripts, with webpack 3.0 the memory spikes up to 5gb and the process dies. With webpack 2 it used to be ok
Update Node versión from v8.16.0 to v12.6.0 and that issue is gone!
upping the memory limit will only solve the problem temporarily but the RAM being used up the more you rebuild the application. You will notice your machine gets slower overtime.
Adding a directory with some large library files to
.eslintignore
fixed the issue for me.Same problem, but using
cheap-module-source-map
at dev builds andfalse
at production. @joshcomley that’s not solution, it’s falls too.My problem was caused because I was using a large JSON file (multiple MBs) to mock a server-side HTTP response. This was a temporary workaround because the server-side endpoint was unders construction. Removing the large file solved the leak. So I would suggest to check the size of your files and split them into multiple files or remove them if possible if they are too large.
Had the same issue. Seems like source of the problem was I hadn’t allocated enough memory to my virtual machine (running ubuntu/trusty64 through Vagrant). I think Vagrant only allocates about 512 MB of memory by default.
Setting
in my Vagrantfile fixed the problem. I should note I’m also running node with
--max_old_space_size=2048
Same issue here, in our case, we use webpack 3.5.6 and webpack-bundle-analyzer 2.9.0, if we use the bundle analyzer plugin and run webpack --watch --progress, the out of memory error will show up. Solution for us is simple, do not use the bundle analyzer when running webpack --watch --progress.
postcss-loader was causing this issue for me. Commenting it out would allow the builds to pass.
The issue was because the VPS I was running the build on had 1024MB RAM but only a 256MB swap disk. Increasing the swap disk size to 2048MB fixed the issue.
Changing
devtool
toeval-source-map
fromsource-map
solved it for me.webpack 3.5.1
My error is directly related to: #5089
@eirikurn Alright. After looking into it, it looks like postcss-loader#2.0.0 did update to postcss#6.0, which appears to include some memory related improvements.
Not sure if this change is what impacted your improvement, but it’s at least good to know. Thanks again.
I think clearing them out like @SimenB said would be a nice option, or maybe there is some way to delete all in-memory files that are no longer in use?