Module discord.js cannot be found Error

discordbot233 is my project name.

throw err;
Error: Cannot find module ‘discord.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)

Object. (/app/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)

It appears that it cannot find the module discord.js even tho in the packages.json there is discord.js. I’ve tried re-adding it and it didn’t work. Tried installing it using terminal same results, I’m not sure what else to try to use to fix this problem so I’m asking here if anyone knows a way to fix this.

Thank you in advance.

Can you share your package.json file and the beginning of your server.js (or index.js) file?

I’d give you the full text however I’m running into “you can’t mention more than 2 users” restriction, sorry.
It’s in the pastebin package.json and server.js (I removed most of the commands from server.js that aren’t really needed because there is alot since I don’t have a command handler.)

Try running this in the terminal:
npm install
npm start

Avoid the use of npm, use pnpm rather (on glitch).

1 Like

I used pnpm install discord.js and it fixed the problem, thanks

1 Like

Thanks for helping(I used pnpm install discord.js and it fixed the problem)

1 Like