Error: Cannot find module 'discord.js' it worked before but it stopped working randomly

ok so basically today the error randomly showed up

internal/modules/cjs/loader.js:892
  throw err;
  ^
Error: Cannot find module 'discord.js'

package.json:

{
  "name": "hello-node",
  "version": "1.0.0",
  "description": "A simple Node app built on fastify, instantly up and running.",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "discord.js": "^13.1.0",
    "fs": "^0.0.2",
    "@discordjs/builders": "^0.6.0",
    "@discordjs/rest": "^0.1.1-canary.0",
    "discord-api-types": "^0.22.0",
    "npm": "^7.22.0",
    "node": "^16.6.1",
    "axios": "^0.21.3",
    "noblox.js": "^4.9.0",
  },
  "engines": {
    "node": "14.17.3"
  },
  "repository": {
    "url": "https://glitch.com/edit/#!/glitch-hello-node"
  },
  "license": "MIT",
  "keywords": [
    "node",
    "glitch",
    "express"
  ]
}

Hard to see how this particular implementation could have worked. I see you are using discord.js 13.1.0 but node 14.17.3 (you will need to specify a more recent version of node like 16.6.1. Also you have npm and node in your list of runtime dependencies which should be there and if fs is the “file system” then it doesn’t need to be installed separately.

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