Search code examples
javascriptnode.jsgulpnodemon

Set --max_old_space_size when running gulp/nodemon


I have a gulp-nodemon task in my gulp process. When I run the process, it gives an error FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory. I guss I have to set max_old_space_size to resolve the issue. However, the process is driven by nodemon instead of node. How can I set the option in my gulp/nodemon task? Here is my gulp/nodemon task:

module.exports = {
  waitForHapi: _waitForHapi,
  nodemon: function () {
    return nodemon({
        script: 'server/server.js',
        ext: 'js',
        ignore: ['client', 'dist', 'node_modules', 'gulpfile.js']
      })
      .on('start', function () {
        fs.writeFileSync('.server-refresh', 'waiting');

       if (!openOpts.already) {
          openOpts.already = true;
          _waitForHapi(function () {
            gulp.src('client/index.html')
              .pipe(open('', openOpts));
          });
        } else {
          _waitForHapi(bwsrsync.reload);
        }
      });
  }

Solution

  • from https://stackoverflow.com/a/38381749/1699320

    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.