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

16

12

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.

Vengeful answered 7/8, 2021 at 13:50 Comment(6)
How are you running your bot? Are you in the correct directory?Spannew
did you installed it with npm install ??Acceleration
@Acceleration I installed discord.js with "npm install discord.js"Vengeful
show your package.json in the directory where you running node index.js.Acceleration
@Spannew I'm running my bot in VSC with node index.js. I just went to the directory and it gives me another error "TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client."Vengeful
@Acceleration package.json "{ "dependencies": { "discord.js": "^13.0.1" } }Vengeful
C
14

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!

Comeaux answered 5/11, 2021 at 4:38 Comment(0)
I
6

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

Insectivorous answered 23/12, 2021 at 23:11 Comment(0)
D
4

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.

Donahoe answered 27/3, 2022 at 14:39 Comment(0)
H
2

root cause, my path was messed up, but I only figured that out once I found where my npm packages where. I had thought they were in ../Programs/Roaming/npm etc but since an update (I think to node) my packages were actually in a Python Lib subdir.

Your Answer might be the same as mine, and I found out all this by using the

npm list -g

Command - which showed the globally installed packages, but also highlighted that this was nowhere to be found in my path

Hope this helps someone!

Hilltop answered 5/10, 2022 at 11:5 Comment(0)
C
1

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.

Charlet answered 1/12, 2021 at 18:34 Comment(0)
A
1

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

Anatola answered 20/4, 2022 at 8:0 Comment(0)
P
1

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.

Plumose answered 14/6, 2022 at 9:28 Comment(0)
R
1

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>

Retardant answered 13/8, 2022 at 10:56 Comment(0)
P
1

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

Peppergrass answered 21/8, 2022 at 10:0 Comment(0)
H
1

When was trying to find 'npm' & 'Rdme' path from command prompt to update the Rdme was getting this error Log

This error is caused when file can't be found or its a wrong path, In my case I added the missing file to respective folders- configured & updated in Environment variables (after adding missing files)

Hillyer answered 12/10, 2022 at 8:23 Comment(0)
K
1

For the coming next. For me I'v got the error when I tried to run a package.json script with the npx run rather npm run.

Khanate answered 22/10, 2022 at 12:26 Comment(0)
L
1

In my case, I used chocolatey to install nodejs and it fixed my issue.

Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following command:

choco install -y nodejs-lts

I hope it works for you too :)

Laurenlaurena answered 21/12, 2022 at 19:53 Comment(0)
V
1

In my case path was giving an issue as per folder structure. I had

"main": "app.js",
"type": "module",
"scripts": {
  "start": "nodemon app.js"
},

I changed it to

"main": "app.js",
"type": "module",
"scripts": {
  "start": "nodemon src/app.js"
},
Vidda answered 21/10, 2023 at 15:15 Comment(0)
O
0

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.

Orgeat answered 7/8, 2021 at 20:24 Comment(1)
I restarted the bot project and this time I turned the intents on for the bot and code, thanks!Vengeful
M
0

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.

Metastasize answered 4/7, 2022 at 18:16 Comment(0)
D
-1

npm uninstall webpack-cli -D

npm install [email protected] --save-dev

than work fine

Disillusionize answered 11/3, 2022 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.