I’m new to JavaScript and trying to deploy my Discord bot on Heroku but running into problems. Every time Heroku attempts to launch the application, it throws an error saying it can’t locate the Discord.js module. I’ve tried searching for answers but I’m still stuck. Has anyone encountered this before and knows what might be causing it? Any help would be really appreciated since I’m just starting out with bot development.
Check your .gitignore file - ignoring node_modules is fine, but don’t ignore package.json or package-lock.json. Also watch out for case sensitivity in your require statement. Use require(‘discord.js’), not require(‘Discord.js’). Heroku runs Linux which is case-sensitive unlike Windows. Run heroku logs --tail to see what’s actually breaking. Sometimes it’s not the module import at all - could be auth tokens or other config issues buried in the logs.
clear your cache b4 deploying? heroku sometimes holds onto old build data. run heroku plugins:install heroku-repo then heroku repo:purge_cache -a yourappname. also check your Procfile - it should be worker: node bot.js not web for a discord bot.
Same thing happened when I first deployed my bot. Make sure your package-lock.json is in your repo - Heroku needs it to install dependencies properly. Also check that your package.json start script points to the right bot file. I wasted hours debugging this before realizing I’d forgotten to commit package-lock.json after running npm install locally. One more thing - check the Node.js version in your package.json engines field. Version mismatches can mess up module resolution during deployment.
Been there with deployment headaches. Discord.js issues usually come down to dependency management, but here’s the thing - you’ll face this same problem repeatedly as your bot grows.
Stop fighting Heroku’s quirks every deployment. Automate the whole process instead. I use Latenode workflows for deployment, monitoring, and auto-restarts when things break.
You can create a workflow that pulls code from GitHub, installs dependencies correctly, deploys to your platform, and sends a Discord message when it’s live. No more guessing about package.json or missing modules.
My bots have been running this way for months without touching deployment. Just push code and automation handles everything.
Check it out: https://latenode.com
hey! make sure discord.js is in your package.json as a dep. if it aint there, run npm install discord.js --save then push it to heroku again. good luck!