Most of the newage javascript framework uses npm for their package management, testing etc. Be it angular, reactjs or any other js requires npm for many of it functionalities. One common issue that people face with npm command is ENOSPC error, especially when you execute the below command
1 |
npm test |
Below is one such error I got while executing the above command. If you are also facing the same then read on, you can fix it pretty easily.
The error here as you can see (in CAPS) is ENOSPC, translates to no space on drive. If you get this error then basically it means you don’t have space on your disk to perform this operation. As a first step, you can check your disk space and make sure that you have enough space. You can also try to clear your /tmp file. After performing these actions still, the issue is not solved then it could be an issue with the inotify.
Before letting you know the fix, I though I will give you a small insight into inotify. You can always skip this and go directly to the solution below.
The manual of inotify defines it as:
1234 The inotify API provides a mechanism for monitoring filesystem events.Inotify can be used to monitor individual files, or to monitor directories.When a directory is monitored, inotify will return events for thedirectory itself, and for files inside the directory.
So basically inotify is an API within Linux kernel to monitor any filesystem events and report it to an application. All the linux distros have set a default limit for inotify. To know the default limit set in your distro, you can execute following command
1 |
cat /proc/sys/fs/inotify/max_user_watches |
In rare cases, this limit needs to be increased for some application to work and that could be the reason for the error we encountered with npm command.
Solution to fix ENOSPC Issue
To fix this ENOSPC issue, execute the following command (For Arch Linux, including arch based distros like Manjaro Linux, read further before executing below commands)
1 2 |
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p; sysctl --system |
If you are running Arch Linux, skip the above commands and add the following entry into /etc/sysctl.d/99-sysctl.conf
1 |
fs.inotify.max_user_watches=524288 |
Now execute
1 |
sysctl --system |
Now if you execute the npm test command, your tests should be executed properly without the ENOSPC error.