Skip to content

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

bash
bun run build

This runs kiln build, which:

  1. Builds the browser bundle into dist/client, with a Vite manifest.
  2. Builds the server bundle into dist/server/server.js.
  3. 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

bash
bun run start

This runs kiln start, which serves the build on port 3000. Set another port with --port:

bash
bunx kiln start --port 8080

kiln 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:

  1. Run kiln build on the build machine.
  2. Copy the project, or at least dist/ and package.json, to the server.
  3. Install production dependencies with bun install --production.
  4. Set the environment variables.
  5. 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:

bash
bunx kiln build --target vercel

This 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:

bash
vercel deploy --prebuilt

Vercel 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, and node: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:

json
{
  "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:

ts
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=production in the host's environment when you run the server yourself.
  • Secrets live in the host's environment, not in committed .env files.
  • defineEnv schemas 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:

bash
bunx kiln test

It 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 build again.
  • Version mismatch errors: all @kiln-js/* packages must match the CLI. Run bun install at the project root.
  • Blank page after deploy: check that the static assets were uploaded, and that config.json routes /(.*) 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.