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));
});
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.
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.
This generally occurs on larger projects where the default amount of memory allocated by Node (1.5gb) is insufficient to complete the command successfully.
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.
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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With