Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp - CALL_AND_RETRY_LAST Allocation failed - process out of memory

Tags:

node.js

gulp

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));
});
like image 792
KVM Avatar asked May 17 '16 10:05

KVM


People also ask

How do I fix JavaScript out of memory?

Open the Start menu, search for Advanced System Settings, and select the Best match. In the Variable name field enter NODE_OPTIONS. In the Variable value field enter --max-old-space-size=4096. This value will allocate 4GB of virtual memory to Node.

How do I fix reached heap limit allocation failed JavaScript Heap out of memory?

To fix JavaScript heap out of memory error, you need to add the --max-old-space-size option when running your npm command. Alternatively, you can also set the memory limit for your entire environment using a configuration file.

Why JavaScript Heap out of memory occurs?

This generally occurs on larger projects where the default amount of memory allocated by Node (1.5gb) is insufficient to complete the command successfully.

How can you avoid fatal error ineffective Mark compacts near heap limit allocation failed JavaScript Heap out of memory?

It is recommended to use the latest version of packages or libraries in building your applications. As we know node version 10 has set the 512MB for memory allocation and you can simply update your node version to the Latest Node and this will fix the issue for you. Giving this command will fix this issue for you.


2 Answers

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.

like image 99
Kevin LeClair Avatar answered Sep 20 '22 05:09

Kevin LeClair


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}
like image 36
azouritis Avatar answered Sep 18 '22 05:09

azouritis