Node.js node:internal/modules/cjs/loader:936 error while trying to use discord.js

Viewed 82528

I'm trying to make a discord bot with the command prefix "*" but when I try to get the bot online/run it, it gives me this error:

node:internal/modules/cjs/loader:936 node:internal/modules/cjs/loader:936 throw err; ^

Error: Cannot find module 'C:\Users\name\const' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

The module I'm using is discord.js and i've installed discord.js on CMD and the VSC terminal but it still comes up with the MODULE NOT FOUND error. I've looked around the internet and I can't find one that fixes the problem. I've tried reinstalling Node.js but it won't stop coming back. Please help, Thanks!

11 Answers

same error with me but I just change file dir cause I run node <filename.js> in the wrong dir so I just change like --- the first step chacks you are in the right dir or not type: > ls then if you are in the right dir then type: node <filename.js> if not then change your dir to change dir type: cd <filename> and then run your first app or file for run type: node <filename.js>

I hope your error is solved!

you need to run it as an administrator so sudo(whatever you tryna run) as long as you are in the right directory

On Windows I solved it like this.

I went to the folder: C:\Users\Documents\AppData\Roaming\npm

And I deleted the file. create-react-app.

I started the project again, and it worked.

I had the same error and it was a case of trying to run the file in node from the wrong location.

My solution was to use the terminal and CD into the exact folder the file I was trying to run were and then after that I could run node filename.js.

In my case (this error ocurred at running docker container of next app), it was because I was running docker-compose without the flag --build, but of without copy lock files (package-lock.json and/or yarn.lock).

I updated my Dockerfile:

[...]

COPY yarn.lock .
RUN yarn install --frozen-lockfile 
CMD [ "yarn", "dev" ]

And after, run with docker-compose up --build

When I was following a JS tutorial i got this error message too. The problem was I copied an existing JS file and renamed it but it through that error when i ran it. When i created a new JS file, and copied the code in, and ran, it worked.

Before starting your server you need to make sure that the start file is mentioned below

cross-env NODE_ENV=production node index<start file name eg:index for index.js>

It happens when you run npm run start without getting into the project first... So, before starting to compile your project, run this command: cd <project folder name>...

It will stop showing the "Missing Module" Error and smoothly run your desired output in your browser

The error tells that you've required packages that you haven't installed. So please make sure that you've installed every package that you've required in your bot. Also if you're sure that you've installed it, please check it again, there were namely some problems for some people that some of their packages got uninstalled while updating Discord.js to version 13.

For your problem in the comments ("TypeError [CLIENT_MISSING_INTENTS]"), it is now required in Discord.js version 13 to add your needed intents in the client. Please read this part of the Discord.js guide.

I fixed this issue by changing the opened directory of the terminal. Just go to the terminal and type: cd <folder name> until you reach the folder in which your js file is located. Then save and run again.

npm uninstall webpack-cli -D

npm install webpack-cli@3.3.12 --save-dev

than work fine

Related