Deploying#
A Kiln app is built into two parts: browser assets and a server bundle. You can run those parts on any machine with a JavaScript runtime, or deploy to Vercel with the Edge adapter. This guide covers both, and the commands that produce each.
Build#
bun run buildThis runs kiln build, which:
- Builds the browser bundle into
dist/client, with a Vite manifest. - Builds the server bundle into
dist/server/server.js. - Prints the size of each output and the runtime and bundler it used.
It loads .env, .env.local, .env.production, and .env.production.local. Set the production values in .env.production or in the real environment of your host. A real environment variable always wins over a file.
Run the build#
bun run startThis runs kiln start, which serves the build on port 3000. Set another port with --port:
bunx kiln start --port 8080kiln start serves files from dist/client directly, with br or gzip compression when the client accepts it. Pages are rendered by the server bundle.
Run kiln build before kiln start. If the manifest is missing, kiln start tells you to build first.
Running anywhere#
Because the server bundle uses standard Request and Response objects, any host that can run a JavaScript runtime can serve it. The basic steps are:
- Run
kiln buildon the build machine. - Copy the project, or at least
dist/andpackage.json, to the server. - Install production dependencies with
bun install --production. - Set the environment variables.
- Run
bunx kiln start --port <port>.
Put a reverse proxy in front of it for TLS, and set a Cache-Control policy for dist/client/assets, because those file names include a content hash.
Deploying to Vercel#
Build with the Vercel target:
bunx kiln build --target vercelThis writes .vercel/output. It contains the static files, the server bundle as one Edge function, and a config.json that routes requests. Deploy the prebuilt output:
vercel deploy --prebuiltVercel serves static files from its CDN. Every other request goes to the Edge function, which renders the page. See @kiln-js/adapter-vercel for the routing details.
Vercel runtime limits#
The function runs on the Edge runtime, not Node.js. Keep these in mind:
- Node-only modules, such as
fs,child_process, andnode:sqlite, are not available. - Use a database client that works over HTTP or WebSockets, not a local file.
- The SQLite auth adapter does not run on Vercel. Use a different adapter, or write one against a hosted database.
- CPU and memory limits apply, so keep heavy work out of the request path.
Configuring headers and redirects#
Add a vercel.json at the project root. The adapter copies these keys into the output:
{
"headers": [
{
"source": "/assets/(.*)",
"headers": [{ "key": "cache-control", "value": "public, max-age=31536000, immutable" }]
}
],
"redirects": [
{ "source": "/old", "destination": "/new", "permanent": true }
],
"rewrites": [
{ "source": "/blog/:path*", "destination": "/posts/:path*" }
],
"cleanUrls": true,
"trailingSlash": false
}Rewrites are applied after static files and before the Kiln catch-all.
Caching pages#
A page can ask a CDN to cache its HTML by exporting revalidate:
export const revalidate = 300;The response then carries s-maxage=300 and stale-while-revalidate. Requests with a cookie are never cached, so signed-in pages are always fresh. See Loaders and actions.
Environment checklist#
- Set
NODE_ENV=productionin the host's environment when you run the server yourself. - Secrets live in the host's environment, not in committed
.envfiles. defineEnvschemas run at startup, so a missing variable stops the deploy from serving traffic. Check the logs after each deploy.
Verifying a build#
Before deploying, run the page checks:
bunx kiln testIt renders each page and reports status codes and errors. Fix any failures first. Then run bunx kiln doctor to check versions.
Troubleshooting#
- "No manifest entry for …": the client entry is not in the build. Check the entry path, and run
kiln buildagain. - Version mismatch errors: all
@kiln-js/*packages must match the CLI. Runbun installat the project root. - Blank page after deploy: check that the static assets were uploaded, and that
config.jsonroutes/(.*)to the function. - A module is missing on Vercel: a Node-only import is in the server code. Remove it or move it behind a web-compatible API.

