Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Getting weird errors when running node index.js w/npm

Okay so I was trying to make a discord bot following a tutorial when I noticed some weird errors.

This is my code:

const Discord = require('discord.js');

const client = new Discord.Client();

const prefix = '-';

client.once('ready', () => {
    console.log('JokeBot is online!')
});

client.on('message', message => {
    if(!message.content.startsWith(prefix) || message.author.bot ) return;

    const args = message.content.slice(prefix.lenght).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('pong!');
    }
});

client.login(YOUR_TOKEN);

And these are the errors:

Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module 'node:events'
Require stack:
- /media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/client/BaseClient.js
- /media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/index.js
- /media/oli/MID/Projects/JS/Bot/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> (/media/oli/MID/Projects/JS/Bot/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) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/client/BaseClient.js',
    '/media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/index.js',
    '/media/oli/MID/Projects/JS/Bot/index.js'
  ]
}
              

May I remind you that running npm install on those packages didn't work and just returned a lot of npm errors. I don't know what to do Edit:

It's still saying that even when I updated node.js

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think the issue is happening because you are using nodejs less than version 16.6.0. discord.js requires node.js version more than or equal to 16.6.0. Try running node -v command in your terminal and that might be less than 16.6.0 then download and install that version of node.

Also add this in your package.json

"engines": {
  "node": ">=16.6.0"
}

Also, in your code, you misspelled length.

enter image description here

about 4 years ago · Juan Pablo Isaza Report

0

in order to use discord.js. So You just need to update nodejs to v16.6. And Your error will be solved.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!