discord.js经济系统报错:Cannot find module './models/UserItems.js'求助
修复discord.js经济系统的模块找不到错误
问题描述
按照discord.js官方指南搭建经济系统时,出现如下错误:
Error: Cannot find module './models/UserItems.js' Require stack: - /home/runner/Banky/dbObjects.js - /home/runner/Banky/index.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/home/runner/Banky/dbObjects.js:12:19) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12)项目路径显示:根目录下有
commands、models文件夹,dbObjects.js、index.js等文件,但models文件夹内仅存在User.js,缺少UserItems.js。
修复方案
- 补全缺失文件:根据discord.js官方指南的内容,在
models文件夹下新建UserItems.js文件,将指南中对应模型代码粘贴进去。 - 核对引用路径:打开
dbObjects.js第12行,检查require('./models/UserItems.js')的拼写是否正确(注意文件名大小写、.js后缀是否遗漏),确认路径层级与实际文件位置匹配。 - 同步项目结构:确保你的项目结构完全匹配官方指南的要求,避免因文件夹或文件缺失导致模块引用失败。
内容的提问来源于stack exchange,提问作者Vlad Andrei
相关产品推荐
相关产品推荐

