SOLVED: Can't find Discord.js module

So I made my first discordbot but i can’t get it running on my raspberryPI.

I am constantly getting this Error when trying to start the bot with node index.js.


Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'Discord.js' imported from /home/pi/discordbot/index.js
    at new NodeError (node:internal/errors:371:5)
    at packageResolve (node:internal/modules/esm/resolve:845:9)
    at moduleResolve (node:internal/modules/esm/resolve:890:18)
    at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:1004:11)
    at Loader.resolve (node:internal/modules/esm/loader:89:40)
    at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {

I have already tried to reinstall Discord.js several times but without any success. Any ideas?
Here is my package.json. Maybe it helps.

  "name": "discordbot",
  "version": "1.0.0",
  "description": "A moderation tool",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "author": "Schreibfheler",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^13.1.0",
    "dotenv": "^10.0.0",
    "express": "^4.17.1"
  "type": "module"

Thanks in advance for any help.

Somewhere you required Discord.js vs discord.js. Are you instaling discord.js or Discord.js?

I tried both of them but none worked.

I’m often confused :slight_smile: Are you saying a) it never worked b) it worked but stopped working c) other bots work but this one doesn’t?

And you’re hosting this on Glitch or your Raspberry Pi?

It never worked and there are no other bots. This is the only one. I am trying to host it on a raspberry PI 2b.

I would recommend that you try a demo bot project that has been shown to work. This will reduce the likelihood that you have introduced an error.

You should also check with any Raspberry PI support group that may have already done this in case there is something “unique” to the PI that (I would guess) folks on Glitch may not have encountered.

1 Like

I have now tried a demo bot. It fixed the discord.js-error but there is another issue. An error gets loged, that my token is wrong. I have now retried and also regenerated my discordbot token but it still posts an error.


    if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');

Error [TOKEN_INVALID]: An invalid token was provided.
    at Client.login (/home/pi/discordbot/node_modules/discord.js/src/client/Client.js:228:52)
    at Object.<anonymous> (/home/pi/discordbot/index.cjs:17:8)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  [Symbol(code)]: 'TOKEN_INVALID'

We have to assume the error is valid right? So that means your token is invalid. So you need to take steps to confirm that the token is either valid (doesn’t seem likely) or you haven’t set the token to the value you believe you have.

These have nothing to do with bots or Raspberry PI or Discord or Glitch. If you have code and it tells you there is a runtime issue you work your way towards the discovery of the cause. Don’t post it here but output the value you “think” you are using to a console and check it. Compare it against the value stored on Discord.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.