NodeJS: Error: Cannot find module 'ytdl-core'

NodeJS: Error: Cannot find module 'ytdl-core'

我在 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 安装模块,但我得到了同样的错误。

您需要但未安装 ytdl-core

请使用命令安装:

npm install ytdl-core

或安装 yarn:

yarn add ytdl-core

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

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

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

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