简体   繁体   中英

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'

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 :(

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

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

NOTE : if this doesnt work please add more screenshots / more info about your file locations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM