Docs › Help › Error fixes
Fix "Error: Cannot find module" in a Node.js Discord bot
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.jsor, 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 #
- Open
package.jsonand check the package is listed under"dependencies"(not onlydevDependencies):
"dependencies": {
"discord.js": "^14.16.0",
"dotenv": "^16.4.0"
}- If it's missing, add it on your computer with
npm install discord.js, which updates package.json, then upload the newpackage.json. - Make sure
package.jsonsits in the top folder next to your start file, not inside a subfolder likemy-bot/. - Check the spelling and case:
require("Discord.js")fails on Linux even if it worked on Windows. - Restart. ESN runs
npm installon 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.jsorsrc/index.js. TypeScript bots point at the built file, likedist/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. Usepath.join(__dirname, "commands")when you load folders. - Case:
Commands/andcommands/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.