Fix "Cannot find module" and "ModuleNotFoundError" for bots
Fix missing package errors when your Discord bot starts on Schokr: add packages to package.json or requirements.txt and check file paths and names.
Updated · 2 min read
"Cannot find module" (Node.js) and "ModuleNotFoundError" (Python) mean your bot tried to load a package or file that isn't on the server. Usually the package isn't listed in package.json or requirements.txt, or a file path is wrong.
What the errors look like
Error: Cannot find module 'discord.js'
Require stack:
- /home/container/index.js
ModuleNotFoundError: No module named 'dotenv'
Node.js: package not in package.json
Packages installed locally but never saved to package.json won't be installed on the server.
- On your computer, run
npm install package-name(this adds it topackage.json). - Upload the updated
package.jsonandpackage-lock.jsonwith the file manager. - Restart the server so dependencies install again.
Check the dependencies section contains everything you require or import:
{
"dependencies": {
"discord.js": "^14.16.0",
"dotenv": "^16.4.0"
}
}
Packages in devDependencies may not be installed in production. Move anything the bot needs at runtime into dependencies.
Node.js: a local file isn't found
If the error names one of your files, like Cannot find module './commands/ping':
- Check the folder was uploaded and the path is right relative to the file doing the
require. - File names are case-sensitive on Linux.
./Commands/Ping.jsand./commands/ping.jsare different files on the server, even if they work on Windows or macOS. - For TypeScript, make sure you're running the compiled
distfolder. See hosting a TypeScript bot.
Node.js: broken node_modules
If you uploaded node_modules from your computer, native packages (like better-sqlite3) may fail with errors about invalid ELF headers or missing .node files. Delete node_modules on the server with the file manager and restart so it reinstalls cleanly.
Python: package not in requirements.txt
- Add the package to
requirements.txtusing its install name. - Upload the file and restart the server.
Install names often differ from import names:
| You import | Add to requirements.txt |
|---|---|
discord | discord.py |
dotenv | python-dotenv |
yaml | PyYAML |
PIL | Pillow |
bs4 | beautifulsoup4 |
Watch the console on start for pip errors. If one package fails to install (for example, a typo), the rest may not install either.
Python: your own modules
- Running a file inside a subfolder changes how imports resolve. Keep your entry file in the server root, or use package-style imports consistently.
- Don't name your own files after libraries (
discord.py,asyncio.py,random.py). Python imports your file instead of the library. - Cogs load by dotted path from the working directory:
cogs/fun.pyis"cogs.fun".
Still stuck?
Post the full error and your dependency file in the Schokr Discord.