Error: Cannot find module 'discord.js'

Hi there,

i am a new coder that trying to code a discord bot with discord js and run into some tutorials in Glitch.com hosting as well. But i seem to hit this error where discord.js is not found from my simple bot file

here is my package.json
{
“name”: “rembot”,
“version”: “1.0”,
“description”: “Test bot”,
“main”: “node rem.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”,
“start”: “node rem.js”
},
“dependencies”: {
“express”: “^4.16.3”,
“discord.js”: “^11.3.2”,
“enmap”: “^2.1.0”,
“moment”: “^2.22.0”,
“moment-duration-format”: “^2.2.2”
},
“engines”: {
“node”: “8.4.0”
},
“repository”: {
“url”: “https://glitch.com/edit/#!/intothefantasy
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”
]
}

Hi @intothefantasy,

your package.json has an error (well, in Glitch it is counted as an error): your version field does not contain a valid semver. This is why the packages don’t get installed. You should set it to 1.0.0 (for example), and then the packages will be installed. If you scroll up in the Logs, you’ll see that this error is reported.

Let us know if this fixes your issue :slight_smile:

1 Like

Hi there

thanks for the response, it fixes my issue after removing the version

1 Like

Hello Can you tell me how you fixed
Step by step
Please.
I am still getting this error. :frowning:

1 Like

In the above scenario, you go into the package.json file and change the value alongside ‘version’ to 1.0.0. However, there are a few potential causes of this problem, so if that doesn’t fix it then provide your project name and we can take a look for you.

Hi, I’m having a similar issue.
Error: Cannot find module ‘discord.js’

at Function.Module._resolveFilename (module.js:489:15)

at Function.Module._load (module.js:439:25)

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

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

at Object. (/app/server.js:1:79)

at Module._compile (module.js:573:30)

at Object.Module._extensions..js (module.js:584:10)

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

at tryModuleLoad (module.js:470:12)

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

:beetle: The debugger could not be started. See https://glitch.com/faq#debugger

My package json:

{

“name”: “l o s t s o u l”,
“version”: “2.0.2”,
“description”: “noot noot”,
“main”: “node server.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”,
“start”: “node server.js”
},
“engines”: {
“node”: “8.4.0”
},
“author”: “Big Sis!”,
“license”: “don’t steal or i kill u”,
“dependencies”: {
“discord.js”: “^11.4.2”,
“dotenv”: “^6.0.0”,
“enmap”: “^4.2.4”,
“express”: “^4.16.3”,
“moment”: “^2.22.2”,
“moment-duration-format”: “^2.2.2”
}
}

Trying to change it to 1.0.0 did nothing for me.

project name: outgoing-actress

The name value you’ve specified in package.json can’t contain spaces, try changing it to ‘lostsoul’

i didn’t do that, but:
all i did was run these under console:

npm install discord.js
npm install dotenv
npm install express

and it worked for me. hope this helps anyone else having this issue. :slight_smile:

2 Likes

Help me! I got the same error but nothing from here helps!
Here’s my code:

{
  "name": "simplebot",
  "version": "1.0.0",
  "description": "A Simple Bot",
  "main": "index.js",
  "engines": {
    "node": ">=8"
  },
  "scripts": {
    "start": "node index.js"
  },
  "license": "MIT",
  "dependencies": {
    "ascii-art": "^1.5.1",
    "axios": "^0.19.0",
    "better-cleverbot-io": "^1.0.2",
    "better-sqlite3": "^5.4.0",
    "chalk": "^2.4.2",
    "cleverbot.io": "^1.0.4",
    "discord.js": "^11.5.1",
    "enmap": "^5.0.0",
    "express": "^4.16.4",
    "express-glitch-keepalive": "^0.2.0",
    "fs": "^0.0.2",
    "hastebin": "^0.0.3",
    "hastebin-gen": "^2.0.5",
    "inquirer": "^6.4.1",
    "mathjs": "^5.10.3",
    "moment": "^2.24.0",
    "moment-duration-format": "^2.3.2",
    "ms": "^2.1.2",
    "node-os-utils": "^1.0.7",
    "nodemon": "^1.19.1",
    "os": "^0.1.1",
    "request": "^2.88.0",
    "systeminformation": "^4.14.8"
  }
}

also I can’t install through console, it returns the Access Denied error

Hey @MinecraftCiach, welcome to the Glitch forum!

When I take a look at the project listed in the json you posted I’m not seeing any installation problems; are you still having issues?

Hi,

I’m having similiar problem and I think that I did everything right.
Here is my config.json file: https://github.com/guliii41/discordbot/blob/master/config.json
and here’s what I get when I try to run my index.js file: https://github.com/guliii41/discordbot/blob/master/issue%20file
Hope someone will help me since I’m new to JS.
Thanks.

No. I don’t have any issues right now.

Does running enable-pnpm in the console help?

Hi ! I have an error do you help me pls ?

PS C:\Users\Eli\Desktop\NinjaBot> node index.js
internal/modules/cjs/loader.js:968
throw err;
^

Error: Cannot find module ‘discordjs’
Require stack:

  • C:\Users\Eli\Desktop\NinjaBot\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object. (C:\Users\Eli\Desktop\NinjaBot\index.js:1:17)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [ ‘C:\Users\Eli\Desktop\NinjaBot\index.js’ ]
    }
1 Like

i have the same problem

Its discord.js not discordjs

  1. its helpful
  2. discord.js is the package name
  3. don’t post about things that you don’t know about
3 Likes

Okay then. I’ll remember that