Node.js: what is ENOSPC error and how to solve?

node.js

node.js Problem Overview


I have a problem with Node.js and uploading files to server. For uploading files to server I use this plugin. When starting file upload to the server, Node.js process crashed and show error:

> Error: ENOSPC.

The server code doesn't run.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.9G  4.1G  3.5G  55% /
udev            288M  8.0K  288M   1% /dev
tmpfs           119M  168K  118M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            296M     0  296M   0% /run/shm
/dev/xvdf       9.9G  3.0G  6.5G  32% /vol
overflow        1.0M  1.0M     0 100% /tmp

node.js Solutions


Solution 1 - node.js

Run the below command to avoid ENOSPC:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf:

fs.inotify.max_user_watches=524288

Then execute:

sysctl --system

This will also persist across reboots. Technical Details Source

Solution 2 - node.js

ENOSPC means that there is no space on the drive.

Perhaps /tmp is full? You can configure npm to use a different temp folder by setting npm config set tmp /path/to/some/other/dir, or maybe delete everything out of the /tmp folder.

Source: npm 1.1.21 cannot write, ENOSPC in npm's repo in github.

Note I solved my problem in the way that described in above source. However, see Murali Krishna's answer, which is more comprehensive.

Solution 3 - node.js

A simple way that solve my problem was:

npm cache clear

npm or a process controlled by it is watching too many files. Updating max_user_watches on the build node can fix it forever. For debian put the following on terminal:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

If you want know how Increase the amount of inotify watchers only click on link.

Solution 4 - node.js

Can't take credit for this, but @grenade pointed out that npm dedupe will fix the cause (too many files) and not the symptom.

Source: Grunt watch error - Waiting…Fatal error: watch ENOSPC.

Solution 5 - node.js

Rebooting the machine solved the problem for me. I first tried wiping /tmp/ but node was still complaining.

Solution 6 - node.js

On Linux, this is likely to be a limit on the number of file watches.

The development server uses inotify to implement hot-reloading. The inotify API allows the development server to watch files and be notified when they change.

The default inotify file watch limit varies from distribution to distribution (8192 on Fedora). The needs of the development server often exceeds this limit.

The best approach is to try increasing the file watch limit temporarily, then making that a permanent configuration change if you're happy with it. Note, though, that this changes your entire system's configuration, not just node.

To view your current limit:

sysctl fs.inotify.max_user_watches

To temporarily set a new limit:

# this limit will revert after reset
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p
# now restart the server and see if it works

To set a permanent limit:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Solution 7 - node.js

On Ubuntu 18.04 , I tried a trick that I used to reactivate the file watching by ionic/node, and it works also here. This could be useful for those who don't have access to system conf files.

CHOKIDAR_USEPOLLING=1 npm start

Solution 8 - node.js

If you're using VS Code then it'll should unable to watch in large workspace error.

"Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)

It indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files. The current limit can be viewed by running:

cat /proc/sys/fs/inotify/max_user_watches

The limit can be increased to its maximum by editing /etc/sysctl.conf and adding this line to the end of the file:

fs.inotify.max_user_watches=524288

The new value can then be loaded in by running sudo sysctl -p.

Note: 524288 is the max value to watch the files. Though you can watch any no of files but is also recommended to watch upto that limit only.

Solution 9 - node.js

If your /tmp mount on a linux filesystem is mounted as overflow (often sized at 1MB), this is likely due to you not specifying /tmp as its own partition and your root filesystem filled up and /tmp was remounted as a fallback.

To fix this after you’ve cleared space, just unmount the fallback and it should remount at its original point:

sudo umount overflow

Solution 10 - node.js

I solved my problem killing all tracker-control processes (you could try if you use GDM, obviously not your case if the script is running on a server)

tracker-control -r

My setup: Arch with GNOME 3

Solution 11 - node.js

If you encounter this error during trying to run ember server command please rm -rf tmp directory. Then run ember s again. It helped me.

Solution 12 - node.js

I was having Same error. While I run Reactjs app. What I do is just remove the node_modules folder and type and install node_modules again. This remove the error.

Solution 13 - node.js

For me I had reached the maximum numbers of files a user can own

Check your numbers with quota -s and that the number under files is not too close to the quota

Solution 14 - node.js

This sounds very odd, but yes, a system reboot or killall node solves the problem for me.

Solution 15 - node.js

Tried most of the things suggested above. At the end deleting node_modules directory helped me.

So I think what worked is:

  1. echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
  2. sudo sysctl --system
  3. rm -r /tmp* (!! make sure this will not break anything for you)
  4. rm -r node_modules
  5. Restart system

Solution 16 - node.js

It indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files. The max limit of watches has been reacherd, you can viewed the limit by running:

cat /proc/sys/fs/inotify/max_user_watches

run below code resolve this issue:

fs.inotify.max_user_watches=524288

Solution 17 - node.js

In my case, I did this

yarn cache clean

npm cache verify

rm -rf node_modules/

yarn install

Solution 18 - node.js

In my case, on linux, sudoing fixed the problem.

Example:

sudo gulp dev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGiffoView Question on Stackoverflow
Solution 1 - node.jsMurali KrishnaView Answer on Stackoverflow
Solution 2 - node.jsBluView Answer on Stackoverflow
Solution 3 - node.jsDanrley PereiraView Answer on Stackoverflow
Solution 4 - node.jsorbitelevenView Answer on Stackoverflow
Solution 5 - node.jsBjorn ReppenView Answer on Stackoverflow
Solution 6 - node.jsWoodrow BarlowView Answer on Stackoverflow
Solution 7 - node.jsManolo de la VegaView Answer on Stackoverflow
Solution 8 - node.jskartik tyagiView Answer on Stackoverflow
Solution 9 - node.jsPradeep KumarView Answer on Stackoverflow
Solution 10 - node.jsDenys VitaliView Answer on Stackoverflow
Solution 11 - node.jsDaniel KmakView Answer on Stackoverflow
Solution 12 - node.jsGhayyas MubashirView Answer on Stackoverflow
Solution 13 - node.jsnericView Answer on Stackoverflow
Solution 14 - node.jsAram ParonikyanView Answer on Stackoverflow
Solution 15 - node.jsShubham JainView Answer on Stackoverflow
Solution 16 - node.jsuser14254291View Answer on Stackoverflow
Solution 17 - node.jsNicolasView Answer on Stackoverflow
Solution 18 - node.jsSebastien ChartierView Answer on Stackoverflow