You can run a TypeScript bot on a Node.js bot server in two ways.
Option 1: run the .ts file directly
Set Main file to your TypeScript file, for example src/index.ts, in Settings, Game Settings. A main file that ends in .ts is started with the tsx runner, so you do not need to compile. Upload your src folder, package.json and tsconfig.json. Put every package your code imports in package.json, including typescript and type packages if your code needs them.
This is the simplest option. Startup is a little slower than compiled JavaScript.
Option 2: compile first, run the JavaScript
- Build on your computer with
npx tsc. - Upload the compiled folder (for example
dist) andpackage.json. - Set Main file to
dist/index.js.
This starts faster and uses a little less memory. Remember to rebuild and upload each time you change the code.
Common problems
Cannot find module: a package is missing frompackage.json. Add it, or add it to Extra npm packages.ERR_MODULE_NOT_FOUNDwith ES modules: relative imports need the file extension when"type": "module"is set. Use./util.js(the compiled name) in TypeScript imports.SyntaxError: Cannot use import statement outside a module: your file usesimportbut Node treats it as CommonJS. Set"type": "module"inpackage.json, or compile to CommonJS.- Types missing at start-up do not stop
tsx. Type errors only matter when you runtscyourself.
Related: How to host a Node.js Discord bot, How to make a Discord bot with discord.js.





