Pavel Perevezencev
Pavel Perevezencev

Reputation: 2978

Webpack out of memory

When I'm working with a webpack-dev server, the problem sometimes occurs

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

more here

Config webpack.config.js

"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dev-server": "^3.1.3",

NodeJS version:

node -v
v9.3.0

OS version:

macOS High Sierra 10.13.6

Has anyone encountered a similar problem?

Upvotes: 27

Views: 53196

Answers (5)

Danyil Suhak
Danyil Suhak

Reputation: 61

I got another approach from here https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114885/diffs?commit_id=edf538c8142c34a07d43d0b6f5dee0250879414c It says it can help with out of memory errors during compilation.

I used command like this:

"NODE_OPTIONS=\"--max-old-space-size=4094\" webpack --watch --env.type development --env.analysis 1"

You can use command like this:

"NODE_OPTIONS=\"--max-old-space-size=[memory-limit-in-megabytes]\" webpack [your-parameters]"

Upvotes: 0

Joshua Goldstein
Joshua Goldstein

Reputation: 297

I tried the solution suggested above of using webpack-dev-server but it hangs(?) or maybe it runs a server. Looking inside my webpack script (version 4.43.0) I did this instead:

node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js

this worked locally and in my jenkinsfile. Run this instead of "webpack"

Upvotes: 5

Amazing Apps
Amazing Apps

Reputation: 239

node --max-old-space-size=8192 node_modules/webpack-dev-server/bin/webpack-dev-server.js

Run above command instead of running npm start

Upvotes: 15

laggingreflex
laggingreflex

Reputation: 34627

Increase your node process's memory limit. Start node with command-line flag --max-old-space-size=2048 (to 2GB, default is 512 MB I think), or set it via environment variable NODE_OPTS https://nodejs.org/api/cli.html

Upvotes: 9

Odyssee
Odyssee

Reputation: 2463

You might get away with the following. The issue is caused by a memory leak in postcss-loader. The one liner below has worked for some.

rm -rf [package-lock.json] node_modules && npm cache clean -f && npm i

For more information: https://github.com/webpack/webpack/issues/6929

Upvotes: 5

Related Questions