Can't find module "discord.js"

So I have been getting this error
module.js:550

throw err;

^
Error: Cannot find module ‘discord.js’
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
Jump Toat Object. (/app/index.js:1:79)
at Module._compile (module.js:653:30)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)

at tryModuleLoad (module.js:506:12)

at Function.Module._load (module.js:498:3)
and I have been trying from deleting the package to doing it in console and nothing seems to work. Is there any way to fully fix it?
also here’s my package list.

Hey @rashed0943,

  1. Try running enable-pnpm in the Console.

  2. Or do npm i discord.js.

A few things

  • remove node.js as a dependency
  • you have discord.js listed as a dependency twice

didn’t work I did both of them and still got the error

I removed it and added discord.js again and it gave a new error now
` /rbd/pnpm-volume/94b7956e-662a-48a3-8072-5a0012dea2a5/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/Client.js:41

} catch {

^

SyntaxError: Unexpected token {

at createScript (vm.js:80:10)

at Object.runInThisContext (vm.js:139:10)

at Module._compile (module.js:617:28)

at Object.Module._extensions…js (module.js:664:10)

at Module.load (module.js:566:32)

at tryModuleLoad (module.js:506:12)

at Function.Module._load (module.js:498:3)

at Module.require (module.js:597:17)

at require (internal/module.js:11:18)

at Object. (/rbd/pnpm-volume/94b7956e-662a-48a3-8072-5a0012dea2a5/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/index.js:8:11)`

Update your Node.js version, and you should be good to go.
You can search on this forum concerning how to update the Node.js version.


I updated the node.js but the bot is still not firing up cus of this error.

Post your package.json file here.

{
“name”: “101-bot-code”,
“version”: “0.0.1”,
“description”: “Discord Bot”,
“main”: “node index.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”,
“start”: “node index.js”
},
“dependencies”: {
“discord.js”: “^12.1.1”,
“dateformat”: “^3.0.3”,
“express”: “^4.16.3”,
“flip-text”: “^1.1.0”,
“jimp”: “^0.2.28”,
“moment-duration-format”: “^2.2.2”,
“moment-timezone”: “^0.5.26”,
“node-time”: “^0.1.0”,
“discord.js”: “^12.1.1”,
“opusscript”: “^0.0.6”,
“request”: “^2.87.0”,
“roblox-js”: “^4.0.2”,
“snekfetch”: “^4.0.4”,
“to-zalgo”: “^1.0.1”,
“urban”: “^0.3.1”,
“node.js”: “^0.0.0”
},
“engines”: {
“node”: “8.x”
},
“repository”: {
“url”: “https://glitch.com/edit/#!/hello-express
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”
],
“directories”: {
“test”: “test”
},
“devDependencies”: {},
“author”: “”
}

The error that I’m seeing there is an error with D.JS 12.1.1, try downgrading.

1 Like

I downgraded and the error pops up and just keeps on spamming

/rbd/pnpm-volume/94b7956e-662a-48a3-8072-5a0012dea2a5/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/Client.js:41
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/rbd/pnpm-volume/94b7956e-662a-48a3-8072-5a0012dea2a5/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/index.js:8:11)

Looks like you didn’t downgrade? The error you pasted includes “/discord.js/12.1.1”.

Also, discord.js is a dependency in your package.json twice.

1 Like

@Anish @rashed,
The error is due to the usage of an older version of Node.
Change the engines fields to version 12.x and you should be good to go.

{
    "engines": {
        "node": "12.x"
    }
}
1 Like

@benborgers, @chroventer the problem fix you two said fixed my project and it’s up in running again thanks to you both of you and some of @Anish help too!