Gulp - CALL_AND_RETRY_LAST Allocation failed - pro

2019-02-13 05:15发布

问题:

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));
});

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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}


回答5:

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" %* )



回答6:

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.



回答7:

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.



标签: node.js gulp