19

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?

Pavel Perevezencev
  • 2,596
  • 3
  • 28
  • 49
  • I am facing the same issue. Little information is available, this probably is a memory leak in Webpack or a npm package. I got this behaviour after upgrading to Webpack 4.16 from 3.x. If I find anything I will let you know – Odyssee Aug 16 '18 at 13:07

5 Answers5

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

Run above command instead of running npm start

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
Amazing Apps
  • 219
  • 3
  • 5
8

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

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
  • 3
    Please note that the actual link is: https://nodejs.org/api/cli.html#node_optionsoptions . `NODE_OPTIONS=--max-old-space-size=2048` something like that – jnelson Nov 02 '21 at 14:17
5

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

Odyssee
  • 2,393
  • 2
  • 19
  • 38
  • 5
    This is vague - what version of postcss-loader has the memory leak? Reinstalling every module because you have a problem with one isn't a good fix. – mikemaccana Aug 10 '21 at 10:17
  • @mikemaccana This issue is over almost 3 years old, I can't remember the specifics, but the line above automagically fixed it for me after wasting hours on finding the exact issue. – Odyssee Aug 10 '21 at 10:22
  • 1
    Sure but it's like reinstalling your OS or getting a new laptop - it might fix the issue, but it's not much of an answer. – mikemaccana Aug 10 '21 at 11:09
4

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"

0

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]"
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34783774) – patrickmdnet Aug 09 '23 at 04:14
  • Yes, I agree, but the link doesn't give much information. I can only add more from myself. – Danyil Suhak Aug 13 '23 at 16:32
  • @patrickmdnet Thanks for the advice. I don't have a lot of experience with answers, so if anything else stabs you in the eye, please post. – Danyil Suhak Aug 13 '23 at 16:39