简体   繁体   中英

How can i fix “Cannot find module './commands/${file}'”

how can i fix this. i want to create a code which is advance commands

code:

 const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
  for(const file of commandFiles){
     const command = require('./commands/${file}');
       
       client.command.set(command.name, command);

Use backticks ` instead of single quotes.

So

const command = require('./commands/${file}');`

Should be

const command = require(`./commands/${file}`);

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