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

19

406

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
Hematuria answered 18/3, 2014 at 9:59 Comment(7)
"ENOSPC" means that there is no space on the drive, so where do you save your file? or maybe /tmp is full?Firepower
I save files in /dev/xvda1 . Can i make rm -rf /tmp/*?Hematuria
yes, but i dont think 1mb is enough for fileuploads, so change the tmp-dir to another location like in the answer from Blu AngelFirepower
Sounds like your use case might be different, but here's a great solution to this problem from another SO question.Amari
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.Archeozoic
All in all, this is using the same solutions as in Grunt watch error - Waiting…Fatal error: watch ENOSPC so probably worth marking this as a duplicate of that one.Bracing
Update your accepted answer, the 2nd answer is the right one.Ave
S
1396

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

Surround answered 16/9, 2015 at 6:10 Comment(8)
Here is what it does. github.com/guard/listen/wiki/…Jerry
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.Surround
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.Surround
This has helped me to solve the problem also this link github.com/guard/listen/wiki/… has all the details. ThanksRoger
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?Burtis
Don't no what happens after running this command, but it works for me!! Thanks @MuraliKrishnaKurr
On Ubuntu, you can put this setting in a separate file in /etc/sysctl.d: echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/60-inotify.conf && sudo sysctl --systemLikeness
How can I run the command in windows?Capacitor
P
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.

Polonium answered 18/3, 2014 at 10:10 Comment(9)
I cleaned /tmp folder and changed npm temp folder, but have the same problem. npm config get tmp show /vol/deploy/tmpHematuria
can you show your out put again ? output that you get After change dirPolonium
events.js:71 throw arguments[1]; // Unhandled 'error' event Error: ENOSPC, writeHematuria
do you have error listener ? if not than write one and then check resulted outputPolonium
in your code are you assign true or false to debug? if false than make it true so all server response will print on consolePolonium
I had this happen to me even when tmp was mounted on root filesystem and I still had 7 gigs of space left. However I deleted everything at tmp, and it all started working again. How can this be so?Slighting
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.Au
@Au that's a much better explanation than the accepted answer. i'd rather know what's going on and potentially adjust my workflow instead of blindly throwing unexplained system config changes at my OSMiniaturize
No, my drive has enough space.Peatroy
L
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.

Leucocratic answered 9/11, 2018 at 7:32 Comment(2)
I have that problem with forever, fixed it when I create the file .foreverignore and add to them folder node_modules.Schlesinger
my problem is on pipeline, node_modules is already on .gitIgnore.Chewning
S
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.

Sanders answered 5/11, 2015 at 18:59 Comment(0)
H
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
Hut answered 23/5, 2019 at 10:0 Comment(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.Randle
M
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
Marathi answered 14/1, 2020 at 0:43 Comment(0)
A
8

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

Aureomycin answered 24/10, 2017 at 12:11 Comment(1)
The problem came back after rebooting . Doing dedupe helped.Jorry
B
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.

Brookner answered 6/7, 2020 at 5:46 Comment(2)
Excellent! Great response, well-documented. A++++Saxecoburggotha
Glad that it helped!!Brookner
I
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
Intrauterine answered 8/1, 2015 at 8:44 Comment(0)
I
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

Incorporeity answered 6/3, 2016 at 15:27 Comment(1)
Forgot to specify it, yep, I was in the same situation: Arch + GNOMEIncorporeity
S
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.

Subminiaturize answered 22/3, 2017 at 21:28 Comment(0)
M
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.

Monongahela answered 30/11, 2018 at 10:23 Comment(3)
this really works, why is it downvoted - it is the question. But it solves the problem, so what you need else?Speciality
Don't know, May be peoples have some personal issue with me. hahahaMonongahela
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.Lancaster
C
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

Corettacorette answered 21/7, 2016 at 14:9 Comment(0)
R
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
Rowley answered 3/12, 2021 at 13:38 Comment(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 commandCapacitor
F
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
Floatfeed answered 10/9, 2020 at 15:44 Comment(0)
B
0

In my case, I did this

yarn cache clean

npm cache verify

rm -rf node_modules/

yarn install
Burkholder answered 15/12, 2021 at 13:3 Comment(0)
A
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.

Ardent answered 5/9, 2023 at 8:19 Comment(0)
B
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).

Bereft answered 16/4 at 16:36 Comment(0)
S
-19

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

Example:

sudo gulp dev
Sassy answered 2/8, 2015 at 6:43 Comment(2)
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).Pliske
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.Hydrogen

© 2022 - 2024 — McMap. All rights reserved.