8less
8less

Reputation: 81

Discord.js: Error: "Cannot find module 'node:events'" after updating to v13

Today I updated my node version from 12.x to 17.1.0 and my discord.js to 13.3.1. The process of updating was successful but after I run my bot, it outputs the error:

Error: Cannot find module 'node:events'
Require stack:
- /home/runner/rice-v13/node_modules/discord.js/src/client/BaseClient.js
- /home/runner/rice-v13/node_modules/discord.js/src/index.js
- /home/runner/rice-v13/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/rice-v13/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19

Also, I noticed that when I installed a new node version via shell it outputs a warning:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

I surfed this question on the Internet and only found answers like "You gotta have node version 16 or higher" but I actually have 17.1.0.

Upvotes: 0

Views: 2419

Answers (2)

Mahdad Borhani
Mahdad Borhani

Reputation: 1

Instead of:

const client = new Discord.Client();

Type:

const client = new Discord.Client({ intents: ["DIRECT_MESSAGES", "GUILD_MESSAGES"] });

Upvotes: -1

LightningBolt
LightningBolt

Reputation: 61

I see that you're using replit for your bot. This error happens when your repl node version is not high enough. You can fix that by using the NodeJS v16 Template (https://replit.com/@RoBlockHead/NodeJS-16). Just fork that repl template and move all your code there.

Upvotes: 1

Related Questions