Building a WhatsApp bot with Baileys is exciting. Deploying it on a server is where most developers start facing strange errors. The bot works perfectly on a local computer, but once uploaded to hosting, problems begin. This guide explains the most common errors and their practical fixes.
This usually happens when the start script is missing in package.json.
"scripts": {
"start": "node index.js"
}
Make sure your main file name matches.
If Heroku or VPS shows Cannot find module, it means dependencies are not listed in package.json.
Run this before uploading:
npm install --save @whiskeysockets/baileys
This happens when the session folder is not saved or gets deleted on restart. Always store session files properly and avoid clearing them.
Make sure you are printing QR in terminal using qrcode-terminal and checking live logs of your hosting.
On VPS, use PM2:
pm2 start index.js --name bot pm2 save pm2 startup
Do not hardcode ports. Let hosting decide environment port automatically.
Use proper error handling and avoid heavy loops in message listeners.
Most deployment errors are small mistakes in configuration. Once you understand these common problems, your WhatsApp bot can run smoothly 24/7 without interruption.