ESN Docs

Docs › Help › Error fixes

Fix "Error: Cannot find module" in a Node.js Discord bot

2 min readUpdated Nov 4, 2026

Node can't find a package or a file your bot needs. It's almost always package.json, the start file setting or a folder in the wrong place.

The error #

Error: Cannot find module 'discord.js'
Require stack:
- /home/container/index.js

or, when Node can't find your start file at all:

Error: Cannot find module '/home/container/index.js'

Both stop the bot right at start with code: 'MODULE_NOT_FOUND'.

Which one do you have? #

  • A package name ('discord.js', 'dotenv', 'axios'): the package isn't installed. Go to Fix a missing package.
  • A path ('/home/container/index.js', './commands/ping'): a file isn't where the code or the start setting says. Go to Fix a missing file.

Fix a missing package #

  1. Open package.json and check the package is listed under "dependencies" (not only devDependencies):
"dependencies": {
  "discord.js": "^14.16.0",
  "dotenv": "^16.4.0"
}
  1. If it's missing, add it on your computer with npm install discord.js, which updates package.json, then upload the new package.json.
  2. Make sure package.json sits in the top folder next to your start file, not inside a subfolder like my-bot/.
  3. Check the spelling and case: require("Discord.js") fails on Linux even if it worked on Windows.
  4. Restart. ESN runs npm install on every start, so the package is installed from package.json.

Still failing? Delete the node_modules folder in Files and start again, so it installs fresh. Never upload node_modules from your PC: packages built on Windows or macOS can break on Linux.

Fix a missing file #

  • Start file: in Startup, Main JavaScript File must match your real file name, for example index.js, bot.js or src/index.js. TypeScript bots point at the built file, like dist/index.js.
  • Unzipped into a subfolder: if Files shows a single folder like my-bot-main/, move its contents up to the top folder.
  • Relative paths: require("./commands/ping") looks next to the current file. Use path.join(__dirname, "commands") when you load folders.
  • Case: Commands/ and commands/ are different folders on Linux.

On ESN Hosting #

Watch the Console during start: you'll see npm install run first. If it prints an error there (for example a typo in package.json), fix that first. See installing packages and upload and start your bot.

FAQ #

It works on my PC. Why not on the server? #

Usually node_modules on your PC has the package but package.json doesn't list it, or the file name case differs. Windows ignores case; Linux servers don't.

Is this the same as Python's ModuleNotFoundError? #

Same idea, different language. For Python see ModuleNotFoundError: No module named 'discord'.

Should I upload node_modules? #

No. Upload package.json (and package-lock.json if you have one) and let the server install packages.

Host your bot 24/7 from $0.50/month →

Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 4, 2026.