简体   繁体   English

UnhandledPromiseRejectionWarning:错误:当我尝试运行我的代码时找不到模块“../database/db”

[英]UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db' when i try to run my code

so i was trying to implement a database for my discord bot but when it try to call on it all i get is所以我试图为我的不和谐机器人实现一个数据库,但是当它尝试调用它时,我得到的只是

UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db' UnhandledPromiseRejectionWarning:错误:找不到模块“../database/db”

heres the bit thats failing这是失败的一点

 const Discord = require('discord.js'); const bot = new Discord.Client(); const fs = require('fs'); const util = require('util'); const mysql = require('mysql2'); let connection; require('dotenv').config(); ///Token for discord bot (async () => { connection = await require('../database/db'); await bot.login(process.env.BOT_TOKEN); })();

and heres my file structure这是我的文件结构

在此处输入图片说明

i tried installing mysql2 globally to see if that work help and it didnt :(我尝试全局安装 mysql2 以查看该工作是否有帮助,但没有 :(

EDIT:编辑: 在此处输入图片说明

someone asked what the file inside database looked like有人问数据库里面的文件是什么样的

Because you didnt give us enough info i cant really help but if your file name your trying to get is db and your file name is index.js then this should work因为你没有给我们足够的信息我真的帮不上忙但是如果你试图获取的文件名是db而你的文件名是 index.js 那么这应该可以工作

connection = await require('./database/db');

NOTE : if this doesnt work please add more screenshots / more info about your file locations注意:如果这不起作用,请添加更多屏幕截图/有关文件位置的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试要求我的javascript文件时找不到模块“ models / PermissionModel”错误 - Cannot find module 'models/PermissionModel' error when I try to require my javascript file 为什么在运行我的代码时会收到错误“UnhandledPromiseRejectionWarning”? - Why am I getting error "UnhandledPromiseRejectionWarning" when running my code? 当我尝试在我的 React 应用程序中运行 npm 测试时出现错误“SyntaxError: Cannot use import statement outside a module” - The error "SyntaxError: Cannot use import statement outside a module" appears when I try to run npm test in my react application 加载React Native:UnhandledPromiseRejectionWarning:错误:找不到模块'View' - Loading React Native: UnhandledPromiseRejectionWarning: Error: Cannot find module 'View' 运行测试时出错“找不到模块” - Error when run the test "Cannot find module " 尝试创建提交时出现错误“找不到模块'eslint-config-strict / es5'” - Error “Cannot find module 'eslint-config-strict/es5'” when I try to create a commit 当我想在本地服务器上运行我的代码时,我总是会收到这种错误“SyntaxError: Cannot use import statement outside a module” - When I wants to run my code in local server i always get this kinds of error “SyntaxError: Cannot use import statement outside a module” 未捕获的类型错误:当我尝试在 chrome 中运行我的代码时,无法读取 null 的属性“addEventListener” - Uncaught TypeError: Cannot read property 'addEventListener' of null when i try to run my code in chrome 当我尝试测试运行我的 MySQL 数据库时收到此错误消息 - I get this error message when I try to test run my MySQL database 错误:当我运行gulp命令时,找不到模块“扳手”,出现此错误 - Error: Cannot find module 'wrench', I'm getting this error, when i run gulp command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM