NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

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.

  1. On your computer, run npm install package-name (this adds it to package.json).
  2. Upload the updated package.json and package-lock.json with the file manager.
  3. 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.js and ./commands/ping.js are different files on the server, even if they work on Windows or macOS.
  • For TypeScript, make sure you're running the compiled dist folder. 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

  1. Add the package to requirements.txt using its install name.
  2. Upload the file and restart the server.

Install names often differ from import names:

You importAdd to requirements.txt
discorddiscord.py
dotenvpython-dotenv
yamlPyYAML
PILPillow
bs4beautifulsoup4

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.py is "cogs.fun".

Still stuck?

Post the full error and your dependency file in the Schokr Discord.