Otaqui.com Blog

Fix “Error: EMFILE, too many open files” from Yeoman / npm

Fix 'Error: EMFILE, too many open files' from Yeoman / npm

I’ve had several occasions where I’ve run npm update or npm -g update and received an EMFILE, too many open files error, with a high correlation to yeoman involvement.

This error is caused by the sheer number of individual files being opened by npm during an update – lots of those packages you installed include source code, tests and lots of their own dependencies. There are a few approaches you can take to deal with this.

Method 1: Remove unwanted packages

The first thing you can do to try and remedy the EMFILE without doing any tinkering is simply to remove any unwanted npm packages and yeoman generators. Bear in mind, you only need a generator to create the project, and it can be got rid off if you aren’t planning on recreating a new project with that skeleton any time soon. For example, I played around with the angular generator, but don’t have any new angular projects coming up, so I can just do this:

npm -g remove generator-angular

Method 2: Run as root

Your root user may well have a higher “soft limit” than your normal user, which will avoid the EMFILE error. Try running the command as root:

sudo npm -g update

Don’t forget that if you normally run global npm commands under your own username that you will want to adjust permissions back once complete:

sudo chown -R USER:GROUP /usr/local/lib/node_modules

Obviously replacing “USER” and “GROUP” in the above command with the right names.

Method 3: Increase the “Soft Limit” for your OS to stop EMFILE from appearing

As the Yeoman Additional FAQ suggests, you can increase the “soft limit” of the maximum number of files by editing your .bashrc or .zshrc file.

Depending on your OS and whether your environment is a virtual machine, you may be able to increase the “hard limit”. Note that the “soft limit” is meant to curb resource usage by users and processes, the hard limit is the most the OS will allow. If you increase the hard limit, you may still need to up the soft limit as well.