409

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
7
  • 3
    "ENOSPC" means that there is no space on the drive, so where do you save your file? or maybe /tmp is full?
    – Jacob A.
    Commented Mar 18, 2014 at 10:03
  • I save files in /dev/xvda1 . Can i make rm -rf /tmp/*?
    – Giffo
    Commented Mar 18, 2014 at 10:11
  • 1
    yes, but i dont think 1mb is enough for fileuploads, so change the tmp-dir to another location like in the answer from Blu Angel
    – Jacob A.
    Commented Mar 18, 2014 at 10:15
  • 3
    Sounds like your use case might be different, but here's a great solution to this problem from another SO question. Commented Apr 29, 2015 at 15:42
  • For anyone stumbling across this, check out this answer as well. Using grunt and gulp can use a lot of watches, so this answer details how to increase that.
    – Seiyria
    Commented Aug 28, 2015 at 22:32

19 Answers 19

1401

ENOSPC means that there is no space on the drive.

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

8
  • 32
    Here is what it does. github.com/guard/listen/wiki/… Commented Jun 18, 2016 at 3:26
  • 6
    It's not a random number. Each used inotify watch takes up 540 bytes (32-bit system), or 1 kB (double - on 64-bit). This comes out of kernel memory, which is unswappable. So, assuming you set the max at 524288, and all were used (improbable), you'd be using approx. 256MB/512MB of 32-bit/64-bit kernel memory. Commented Apr 5, 2017 at 11:19
  • Theoretically there is no max value, as long as you have enough RAM. In practice, 524288 has been officially recommended by apps, and people have been setting it to 2 million, with the accompanying memory usage. Commented Apr 5, 2017 at 11:23
  • This has helped me to solve the problem also this link github.com/guard/listen/wiki/… has all the details. Thanks
    – amitsin6h
    Commented Jun 13, 2019 at 16:10
  • Does anyone else find it strange that the error that comes out is simply ENOSPC? Why not have a description right after the output like ENOSPC - no space on drive? Sure, the error code makes sense once you know what it means (Error NO SPaCe), but why not just give users that info up front?
    – Shadoninja
    Commented Jun 21, 2019 at 15:16
86

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.

9
  • I cleaned /tmp folder and changed npm temp folder, but have the same problem. npm config get tmp show /vol/deploy/tmp
    – Giffo
    Commented Mar 18, 2014 at 10:30
  • can you show your out put again ? output that you get After change dir
    – Blu
    Commented Mar 18, 2014 at 10:40
  • events.js:71 throw arguments[1]; // Unhandled 'error' event Error: ENOSPC, write
    – Giffo
    Commented Mar 18, 2014 at 10:47
  • 1
    do you have error listener ? if not than write one and then check resulted output
    – Blu
    Commented Mar 18, 2014 at 10:52
  • 76
    wrong, this error happens often in developer workspaces when watching files (via grunt / gulp). This has to do with a unix limit of how many files a process can watch (native watch). The other answer (echo fs.inotify.max_user_watches=524288) is the solution in those cases.
    – cancerbero
    Commented Oct 16, 2015 at 23:13
33

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.

2
  • 2
    I have that problem with forever, fixed it when I create the file .foreverignore and add to them folder node_modules. Commented Mar 7, 2019 at 8:39
  • my problem is on pipeline, node_modules is already on .gitIgnore. Commented Feb 15, 2023 at 17:05
28

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.

0
9

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
1
  • 1
    This can also be really useful for CI build pipelines as if they run under Docker containers or other chroot style isolation you probably can't touch the system files, plus they are only triggering "changes" as they compile the code, they won't be actually editing files where it needs a hot reload functionality.
    – dragon788
    Commented Apr 14, 2021 at 16:26
9

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
0
8

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

1
  • The problem came back after rebooting . Doing dedupe helped. Commented Nov 29, 2018 at 19:02
6

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.

2
  • Excellent! Great response, well-documented. A++++
    – kmiklas
    Commented Jul 27, 2020 at 4:57
  • 1
    Glad that it helped!! Commented Jul 27, 2020 at 5:59
2

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

1
  • 1
    Forgot to specify it, yep, I was in the same situation: Arch + GNOME Commented Mar 23, 2016 at 15:32
2

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
2

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.

2

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.

3
  • this really works, why is it downvoted - it is the question. But it solves the problem, so what you need else? Commented Jun 25, 2019 at 15:35
  • 2
    Don't know, May be peoples have some personal issue with me. hahaha Commented Jul 1, 2019 at 9:05
  • I haven't voted on this answer, but it doesn't provide any explanation as to why removing node_modules solves the problem, and that makes it a poor answer in my view. As a programmer I want to understand the root cause of problems rather than blindly applying workarounds. Commented Oct 6, 2022 at 13:42
1

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

1

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
1
  • How to perform these steps in windows system, when I tried to run echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p in CMD, it sys "sudo" is not recognized as command
    – sarbashis
    Commented Dec 10, 2021 at 6:38
0

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
0

In my case, I did this

yarn cache clean

npm cache verify

rm -rf node_modules/

yarn install
0

My case was different from that of the question in that I was left with no disk space in the system partition (in my case /dev/root) following a system upgrade with the command: sudo apt update && sudo apt upgrade -y.

I tried several solutions included above, but nothing helped until I ran the command:

sudo apt-get clean

As stated here:

The apt-get clean command helps to clean out the cache once you have installed the packages using apt-get install command in your system. It removes the files that are no longer required but are still residing on your system and keeping the system space.

0

I've got the error on Windows 10 using a node.js client application which was writing a 4GB+ file to a FAT32 drive. FAT32 doesn't support a file size larger than 4GB, so it does make sense.

  [ERROR] Error: ENOSPC: no space left on device, write
  ...
  errno: -4055,
  syscall: 'write',
  code: 'ENOSPC'

My solution was to change the output path to another drive (with NTFS file system).

-19

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

Example:

sudo gulp dev
2
  • 6
    This is dangerous! It likely succeeded because a certain percentage of disk space is reserved for root, which doesn't address the core problem – no space available as the unprivileged user (at the target location). Commented Aug 31, 2015 at 4:04
  • Using sudo is a great way to make things happen, but most people neglect to understand everything that happens when sudo is used. Particularly with npm, and npm modules, using sudo can result in things being performed by root which the user doesn't want to have be performed by root, such as file creation or use of protected ports. Basically, the "use sudo" advice falls flat on its face (perhaps after stumbling and staring into the sun for a moment) where nvm/npm/node is concerned.
    – Schlueter
    Commented Aug 1, 2016 at 22:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.