Node.js:什么是ENOSPC错误以及如何解决?

本文探讨了Node.js在文件上传过程中遇到的ENOSPC错误,详细解析了错误原因,包括磁盘空间不足、临时文件夹配置不当及文件观察者限制等问题,并提供了多种解决方案,如清理/tmp目录、修改内核参数和使用sudo权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Node.js: what is ENOSPC error and how to solve?

I have a problem with Node.js and uploading files to server. 我在使用Node.js并将文件上传到服务器时遇到问题。 For uploading files to server I use this plugin . 为了将文件上传到服务器,我使用了这个插件 When starting file upload to the server, Node.js process crashed and show error: 开始将文件上传到服务器时,Node.js进程崩溃并显示错误:

Error: ENOSPC. 错误: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

#1楼

参考:https://stackoom.com/question/1WIzh/Node-js-什么是ENOSPC错误以及如何解决


#2楼

ENOSPC means that there is no space on the drive. ENOSPC表示驱动器上没有空间。

Perhaps /tmp is full? 也许/tmp已满? 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. 您可以配置npm通过设置使用不同的临时文件夹npm config set tmp /path/to/some/other/dir ,也许删除所有出的/tmp文件夹中。

Source: npm 1.1.21 cannot write, ENOSPC in npm's repo in github. 来源: npm 1.1.21无法编写, github中npm的repo中的ENOSPC

Note I solved my problem in the way that described in above source. 注意,我以上述资源中描述的方式解决了我的问题。 However, see Murali Krishna's answer below, which is more comprehensive. 但是,请参阅下面的Murali Krishna的答案 ,该答案更为全面。


#3楼

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. 如果您在Linux文件系统上的/tmp挂载被安装为溢出(通常大小为1MB),则可能是由于您未将/tmp指定为其自己的分区,并且您的根文件系统已填满,并且/tmp被挂载为后备。

To fix this after you've cleared space, just unmount the fallback and it should remount at its original point: 要在清除空间后解决此问题,只需卸载后备,它应该在原始位置重新安装:

sudo umount overflow

#4楼

In my case, on linux, sudoing fixed the problem. 以我为例,在Linux上,sudoing解决了该问题。

Example: 例:

sudo gulp dev

#5楼

Run the below command to avoid ENOSPC: 运行以下命令以避免使用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 : 对于Arch Linux,将此行添加到/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 技术细节来源


#6楼

Can't take credit for this, but @grenade pointed out that npm dedupe will fix the cause (too many files) and not the symptom. 对此不敢恭维 ,但@grenade指出npm dedupe Dedupe将解决问题的原因(文件过多),而不是症状。

Source: Grunt watch error - Waiting…Fatal error: watch ENOSPC . 来源: Grunt观看错误-等待中…致命错误:观看ENOSPC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值