You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu服务器安装discord.js遇ENOTDIR错误求助

解决npm安装discord.js时出现的ENOTDIR错误

在Ubuntu服务器执行命令npm install discord.js安装discord.js时,出现如下ENOTDIR错误:

npm ERR! Linux 4.15.0
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "discord.js"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /root/Minebot/node_modules/.staging/@types/ws-24e3a2dd/package.json
npm ERR! code ENOTDIR
npm ERR! errno -20
npm ERR! syscall open

npm ERR! ENOTDIR: not a directory, open '/root/Minebot/node_modules/.staging/@types/ws-24e3a2dd/package.json'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /root/Minebot/npm-debug.log

解决方案

  • 强制清理npm缓存:
    npm cache clean --force
    
    旧版本npm(如v3.5.2)缓存容易损坏,强制清理可修复.staging目录的异常问题。
  • 删除残留的依赖目录和锁文件:
    rm -rf node_modules
    rm npm-shrinkwrap.json  # 若存在则执行
    
  • 升级npm到适配版本:node v8.10.0建议搭配npm v6.x(v3版本兼容性较差),执行:
    npm install -g npm@6
    
  • 重新执行安装命令:
    npm install discord.js
    

错误原因

该错误是因为npm临时staging目录(/root/Minebot/node_modules/.staging/@types/ws-24e3a2dd)并非合法目录,通常由缓存损坏、旧版本npm的bug或之前安装残留的异常文件导致。

内容的提问来源于stack exchange,提问作者Eloi DOLLE Overlord

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 23:24:40