【问题标题】:NodeJS: Error: Cannot find module 'ytdl-core'NodeJS:错误:找不到模块'ytdl-core'
【发布时间】:2018-12-21 21:21:33
【问题描述】:

我在 NodeJS 中创建了一个不和谐的音乐机器人,也使用了 discord.js,但是每当我运行它时,我都会收到此错误:(文件未命名为 module.js)

module.js:549
    throw err;
    ^

Error: Cannot find module 'ytdl-core'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module.__load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Matthew\Desktop\discord bot\bot.js:2:12)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

起初,我以为是因为我需要像使用 discord.js 一样 npm install 模块,但我得到了同样的错误。

【问题讨论】:

  • 所以npm i ytdl-core 给了你完全相同错误?
  • 是的。但是我确实 npm install ytdl-core,但我认为这不会改变任何东西。

标签: node.js require


【解决方案1】:

您需要但不安装ytdl-core

请用命令安装:

npm install ytdl-core

或使用yarn 安装:

yarn add ytdl-core

【讨论】:

    【解决方案2】:

    正如您提到的,您已经完成了npm install ytdl-core,但仍然出现错误。

    1. 请确保已安装ytdl-core
    2. 日志表明bot.js 需要ytdl-core。所以,请确保你有

    var ytdlCore = require("ytdl-core");

    希望对您有所帮助。或者请添加更多代码以便我区分错误。

    【讨论】:

      猜你喜欢
      • 2020-03-31
      • 2017-12-06
      • 1970-01-01
      • 2017-02-08
      • 2016-06-29
      • 1970-01-01
      • 2018-02-26
      • 2013-09-29
      • 1970-01-01
      相关资源
      最近更新 更多