"EMFILE: too many open files error" while CI/CD deploy

Hello, I got the EMFILE error when launching the serverless “deploy” script. I used the graceful-fs package like this to solve the issue :

  1. install graceful-fs: npm install graceful-fs
  2. go to file: node_modules/serverless/lib/plugins/package/lib/zip-service.js
  3. replace this line :
const fs = BbPromise.promisifyAll(require('fs'));

by this:

var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs)
const fs = BbPromise.promisifyAll(realFs);
1 Like