简体   繁体   English

如何修复“找不到模块 './commands/${file}'”

[英]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}`);

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

相关问题 react-scripts 启动错误(找不到模块'../scripts/start') - 我该如何解决这个问题? - react-scripts start error (Cannot find module '../scripts/start') - how can i fix this? 如何修复显示“找不到模块'mailosaur'”的错误 - How do i fix an error that reads "Cannot find module 'mailosaur'" 接收找不到模块错误,我该如何解决? - Receiving cannot find module error, how do I fix it? 尝试与文件类型模块一起使用时出现笑话错误。 如何修复“无法在模块外使用导入语句”? - Jest error while trying to use with the file-type module. How can I fix "Cannot use import statement outside a module"? 如何修复在 Angular 4 中找不到模块“打字稿”? - How to fix Cannot find module 'typescript' in Angular 4? 错误:找不到模块“./commands/0” - Error : cannot find module './commands/0' 如何修复 WebStorm 中的“找不到要转到的声明”? - How can I fix “cannot find declaration to go to” in WebStorm? npm测试时“找不到模块”如何解决 - How can I solve "cannot find module" when npm test 错误:找不到模块 './commands/${f}1' - Error: Cannot find module './commands/${f}1' 如何修复运行“找不到模块”错误的 docker 容器? - How to fix docker container running 'cannot find module' error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM