"Cannot find module 'discord.js'" error

This is my code (minus my token):


This code worked completely fine about an hour ago, then suddenly it didn’t. I started randomly getting this error:

C:\Program Files\nodejs\node.exe .\index.js
Process exited with code 1
Uncaught Error: Cannot find module ‘Discord.js’

I have tried the following:
-Uninstalling discord.js, then reinstalling it.
-Checking to see if the ‘Discord’ should be capitalised or not.
-Changing the version on the ‘version’ of my package.json.
-Completely rewriting my code from scratch in a new file.
-Reducing the code to just that first line of code.
(Edit: I also tried running Visual Studio Code in administrator mode and I tried tweaking the code such that I provided an exact file location instead of just ‘discord.js’. Again, neither of these worked.)

None of these have worked. I am basically brand new to coding (hence the very simple code) and just fancied messing around with it, but I have genuinely no idea what caused my issue or how to fix it as I have checked everything I can think of.

Any ideas ?

oh wait i didnt saw you downloaded discord.js , can you please paste here your logs? (if there is more of error)

Was it Discord.js or discord.js in the error message?

1 Like

Note that the official package is discord.js. This error can generally be fixed by running npm i discord.js in the project’s terminal.

There aren 't any further error messages unfortunately :confused:

I’ve had error messages with both, although I am aware that the lowercase name is the correct one

Tried this but no luck :frowning:

So in raw defiance to this useless community, I now have a working bot, although admittedly I just found a guide that worked (previous ones didn’t, I still don’t know why), then copied their code.
The guide can be found here:

Maybe installing ‘discord.io’ directly into the same folder as the code might have been the fix ? Although I’m not sure why that would be it if fiddling with the directory didn’t work ?

Either way, I hope this helps anyone with the same issue !