13

When calling one of my gulp task, I get "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory".

I found in this question that I can pass a parameter to node to increase the default memory limit : node --max-old-space-size=2000 server.js. But how can I tell gulp to pass a parameter to node.exe ? Here is the list of flags I can pass to gulp, I was hoping to find one that gulp passes to node when it launches it for a task.

The task causing the issue :

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');

gulp.task('imagemin', function() {
  var OUTPUT_FOLDER = '../Release_Prepared/';
  var extensionsToOptimize = ['gif', 'jpeg', 'jpg', 'png', 'svg'];
  var glob = [];

  for(var i=0; extensionsToOptimize.length; i++){
    glob.push(OUTPUT_FOLDER + '**/*.' + extensionsToOptimize[i]);
  }

  gulp.src(glob)
  .pipe(imagemin({
    verbose: true
  }))
  .pipe(gulp.dest(OUTPUT_FOLDER));
});
Community
  • 1
  • 1
KVM
  • 878
  • 3
  • 13
  • 22
  • If your on windows you need to do a bit differently using set, e.g " SET variable=string" so you would do "set max-old-space-size=2000" and then node.exe server.js but you might want to solve your memory issue instead of just increasing the memory.... – ryanc1256 May 17 '16 at 10:08
  • 1
    Windows has no issues with `node --max-old-space-size=2000 server.js`, it understands `programName --parameter` just fine. My question is how do I pass node parameters from a gulp task ? – KVM May 17 '16 at 12:08
  • Those Arguments get sent directly to V8 (engine behind Node), you don't need to pass it as an argument to a gulp task... There are plenty of good docs on setting those commands. – ryanc1256 May 17 '16 at 22:24

7 Answers7

35

I just found out today that gulp can be given any V8 option and it will be passed to node. For example, do gulp yourTask --max_old_space_size=2000 and it will give you the results you want. To see a list of V8 flags to pass, type node --v8-options in your terminal.

Kevin LeClair
  • 374
  • 2
  • 3
6

In our case First time it was Fine when i was executing gulp build command. I have Four separate tasks. Each task creates separate built files for each modules. we have been running Gulp command for the final build.

There we faced the process out of memory issue continuously. Even though if we allocate large memory to the process. Like below - around 8GB. But, still it was failing.

gulp --max-old-space-size=8192

Solution:

  1. Just delete the previous built files which is created already. And the above command creates the new file. So the process works seamlessly.

For example: Delete main-built.js Manually / Through automation commands.

  1. In other case just clear the cache by executing the below command.

npm cache clean

  1. Since we had large amount of JS files. that is also another case, it could cause this kind of problems. Remove unwanted and unused Js files.

Hope this helps.

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
2

I believe you should run this kind of command when you start the bash script build

node --max-old-space-size=2000 ./node_modules/.bin/gulp {your gulp script e.g gulb.js}
azouritis
  • 85
  • 6
1

I was able to solve this issue by manually deleting my built js/css (dest) files, then re-running the gulp task. This goes along with RJK's answer above, but did not have to allocate new memory.

sternmd
  • 635
  • 2
  • 8
  • 15
0

Search for gulp.cmd and modify that file like this:

@IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0\node_modules\gulp-cli\bin\gulp.js --max-old-space-size=1400" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node "%~dp0\node_modules\gulp-cli\bin\gulp.js --max-old-space-size=1400" %* )

neodigm
  • 11
  • 3
0

Give more memory not solved to me. What happen:

I lost some days with this problem, until I found that in some file I was importing a class from one static file, a builded file. It make the build process to never end. Something like:

import PropTypes from "../static/build/prop-types"; 

Fixing to the real source solved all the problem.

Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
0

I had a simple project that ended up using gulp-imagemin, and had the same issue. The root issue was having LARGE marketing images and Gulp/Node just ran out of memory.

I could of course perform the accepted answer here. But these 4,000+ by 3,000+ pixel images had no business going up on the web anyways, and this error really just reminded me I missed re-sizing some of my images.

So if you get a similar error, check that you have appropriate sized images as gulp/node shouldn't choke on most normal sized builds.

Mechow
  • 45
  • 5