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

执行npm install discord.js后仍提示Cannot find discord.js错误的解决方法

解决Node.js无法找到discord.js模块的问题
  • 先确认终端当前路径是否是项目根目录(index.js所在文件夹)。如果路径错了,Node会在错误位置找依赖。用cd 你的项目绝对路径切换后,再重新运行node index.js。
  • 清理旧依赖后重装:删掉项目里的node_modules文件夹和package-lock.json文件,再执行npm install discord.js,装完再跑脚本。
  • 检查权限:Windows系统下右键终端选「以管理员身份运行」,再重新执行npm install discord.js,避免权限不足导致安装不全。
  • 核对package.json:打开项目根目录的package.json,看dependencies里有没有discord.js。没有的话手动加进去(比如"discord.js": "^14.x.x"),再执行npm install。
  • 版本兼容问题:如果全局Node和项目本地Node版本不匹配,试试用npx node index.js运行脚本,或者确保安装的discord.js版本和Node版本兼容(比如discord.js v14需要Node.js 16.9.0+)。

内容的提问来源于stack exchange,提问作者Nethinat

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 19:57:00