Build it to JavaScript, then run the output
Node.js runs JavaScript, so compile the TypeScript first and start the file it emits. On Bothosting, choose the discord.js profile, upload your source with package.json, the lockfile and tsconfig.json, then set RUN_COMMAND to install, build and start. Save the token as BOT_TOKEN. A small bot runs on the free Spark plan.
Set up the package scripts
"scripts": {
"build": "tsc",
"start": "node dist/index.js"
}npm ci --include=dev && npm run build && npm start--include=dev installs TypeScript when it is in devDependencies. If compiling uses too much memory on a small plan, build on your machine, upload dist, and use npm ci --omit=dev && npm start instead.
Fix the common startup errors
- Cannot find module dist/index.js. Check
outDirandrootDir. With source insrcand norootDir, output can land indist/src/index.js. - Cannot use import statement outside a module. Make the module settings agree:
"type": "module"inpackage.jsonwith"module": "NodeNext"in tsconfig, or CommonJS in both. See npm ci failures for lockfile issues. - ts-node in production. It works but uses more memory and starts slower. Prefer compiled output.
Check the build that is running
Log a version string on ready and change it with each release. After a push or upload, look for the new string in Console, then run a slash command. To deploy on every push, connect the GitHub branch. For first-time setup, see deploying your first Discord bot.