How to run a TypeScript app on Schokr
Run TypeScript on Schokr: compile with tsc and run the JavaScript, use tsx on Node.js, or run .ts files directly with Bun.
Updated · 2 min read
Node.js cannot reliably run your TypeScript source as-is in production, so on Schokr you have three options: compile to JavaScript and run that, run it through a loader like tsx, or use the Bun template, which runs .ts files directly.
Option 1: compile with tsc (recommended for Node.js)
tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true
},
"include": ["src"]
}
package.json scripts:
{
"scripts": {
"build": "tsc",
"start": "node dist/index.js"
}
}
Build on your computer with npm run build, upload the dist folder with package.json and the lock file, and set the main file to dist/index.js in your server's Startup settings. Building locally keeps the server lean, because typescript can stay a dev dependency.
To build on the server instead, the start command becomes npm run build && npm start, and typescript must be installed there.
Option 2: tsx on Node.js
tsx runs TypeScript directly without a separate build:
{
"dependencies": { "tsx": "^4.19.0" },
"scripts": { "start": "tsx src/index.ts" }
}
It does not type-check; it just strips types. Startup is a little slower and memory use a little higher than compiled JavaScript, but it is simple. Keep tsx in dependencies, not devDependencies, if the server installs production dependencies only.
Recent Node.js versions can also strip types natively, but the feature has changed between versions. If you rely on it, check the Node.js docs for the version your server runs.
Option 3: Bun
On a Bun server, set the main file to src/index.ts and you are done. Bun transpiles TypeScript on the fly. See deploying a Bun HTTP server.
Which to choose
| tsc build | tsx | Bun | |
|---|---|---|---|
| Build step | Yes | No | No |
| Type-checks | Yes, at build | No | No |
| Runtime overhead | None | Small | None |
| Best for | Production Node.js apps | Quick deploys, bots | New projects |
Common errors
Unknown file extension ".ts": Node.js is running a.tsfile directly. Use one of the options above.Cannot find module './utils'after compiling: withNodeNext, write imports as./utils.jsin your TypeScript source; the compiled file uses that path. See module not found.- Path aliases like
@/libfail at runtime:tscdoes not rewrite aliases. Use relative imports, a bundler, or a tool such astsc-alias. - Build killed: compiling large projects uses memory. Build locally or see memory limits.
Always type-check locally with tsc --noEmit before uploading, whichever option you use.