Retrieved article excerpt
Open article · Retrieved 2026-10-30T02:25:58.764006+00:00
# Lasm
**Lean 4 for the JavaScript and WebAssembly world.** Lasm compiles ordinary Lean 4
programs ahead of time to WebAssembly. One Lean code base can become a Node server,
a serverless or edge function, a WASI/Fastly module or a browser app. Because it is
Lean, you can prove properties of the code you deploy. The flagship example,
[Conduit](https://github.com/Millillion/lasm#flagship-example-conduit-with-117-proved-theorems), is the RealWorld app
with 117 proved theorems. Lasm ships on npm and brings
Lean, Lake and its build tools with it; you only need Node (or Bun or Deno).
```
npm create @lasm@latest my-app -- --template hono # then: cd my-app && npm install && npm run dev
```
AI agents: this README is complete on its own. [`llms.txt`](https://github.com/Millillion/lasm/blob/main/llms.txt) is the short
index, and [docs/AI.md](https://github.com/Millillion/lasm/blob/main/docs/AI.md) lists the rules that save you from wrong turns.
If Lasm is useful to you, I'd appreciate your [sponsorship](https://github.com/sponsors/lastmjs) ([more below](https://github.com/Millillion/lasm#support-lasm)).
## Quick facts
| Fact | Value |
| --- | --- |
| Current version | `@lasm/cli` 0.3.5 ([release notes](https://github.com/Millillion/lasm/blob/main/docs/release)); `npm view @lasm/cli version` |
| Install | `npm install -D @lasm/cli` (bin: `lasm`), or no install: `npx @lasm/cli …`; new project: `npm create @lasm@latest` |
| Lean | exactly **4.35.0** (`lean-toolchain`: `leanprover/lean4:v4.35.0`); Lasm installs it, and you need no elan to build |
| Develop on | Linux x64/arm64 (glibc 2.34+), macOS x64/arm64, Windows x64 |
| Compiler runs on | Node ≥ 24 (tested 24.0.0, 24.22.1, 26.12.1); Bun 1.4.4 and Deno 2.9.6 (tested, as the only runtime) |
| Output | `dist/` with `program.wasm` + a JS launcher (Node); or a platform package (`--target …`) |
| Node apps run on | Node ≥ 24, Linux x64/arm64 (glibc 2.28+ or musl) from any build machine, plus the build machine's own OS; ≥ 512 MB memory |
| JS/npm interop | `import Lasm.JS`; one `@[js "pkg" "export"]` line per function you call; no premade bindings ([guide](https://github.com/Millillion/lasm/blob/main/docs/JS_BINDINGS.md)) |
| Frameworks in Lean | `Lasm.Fetch` (HTTP, every server target), `Lasm.UI` (browser, Elm architecture, proved diff), `Lasm.RPC` (typed client/server API), `Lasm.Web` (DOM and web APIs), `Lasm.KV` |
| Not available at run time | elaboration, `#eval`-style evaluation, loading `.olean`, Lean's kernel ([exact list](https://github.com/Millillion/lasm#lean-support-and-restrictions)); all of these work at build time |
| License | MIT (Lasm); templates, examples and README code samples also MIT-0 |
| Repository / issues | <https://github.com/Millillion/lasm> · [report a bug](https://github.com/Millillion/lasm/issues/new?template=bug.yml) (include `npx lasm --version`) |
## Platforms
Every row is tested in CI with the platform's own local runtime, image or emulator.
By project policy CI never deploys to a real cloud account
([how each is tested](https://github.com/Millillion/lasm#supported-platforms)).
| Deploy to | `lasm build Main.lean --target …` | Output | Since |
| --- | --- | --- | --- |
| Node server or program (any host, Docker/Kubernetes, Cloud Run, Fly.io, Railway, Render, Heroku, DigitalOcean) | `node` (default) | `dist/` → `node dist/main.mjs` | 0.1.0 |
| AWS Lambda (.zip, `nodejs24.x`) | `lambda` | `lambda.zip` | 0.1.0 |
| AWS Lambda (container image) | `lasm init … --deploy lambda` | `Dockerfile.lambda` | 0.1.0 |
| Lambda@Edge | `lambda-edge` | `lambda-edge.zip` | 0.1.0 |
| Vercel Functions | `vercel` | `.vercel/output` | 0.1.0 |
| Netlify Functions | `netlify` | `netlify/functions/lasm` | 0.1.0 |
| Azure Functions | `azure` | `azure-functions/` | 0.1.0 |
| Google Cloud Functions (gen2) | `gcf` | `gcf/` | 0.1.0 |
| Cloudflare Workers | `workers` | `workers/` | 0.2.0 |
| Vercel Edge | `vercel-edge` | `api/lasm.mjs`, `api/_lasm/` | 0.2.0 |
| Netlify Edge | `netlify-edge` | `netlify/edge-functions/lasm.mjs` | 0.2.0 |
| Deno Deploy | `deno-deploy` | `deno/main.mjs` | 0.2.0 |
| Supabase Edge Functions | `supabase-edge` | `supabase/functions/<name>/` | 0.2.0 |
| Bun (≥ 1.3.14) / Deno (2.x) | `bun` / `deno` | `bun/main.mjs` / `deno/main.mjs` | 0.2.0 |
| Fastly Compute | `fastly` | `bin/main.wasm`, `pkg/<name>.tar.gz` | 0.3.0 |
| WASI (wasmtime, wasmer, `node:wasi`) | `wasi` | `wasi/main.wasm` | 0.3.0 |
| wasi-http (`wasmtime serve`, Spin) | `wasi-http` | `wasi-http/main.wasm` | 0.3.0 |
| Browsers (Chrome, Edge, Firefox, Safari) | `browser` (or the Vite plugin `@lasm/cli/vite`) | `dist/` static site | 0.3.0 |
Node builds have Lean's full runtime (threads, files, processes, sockets). The
edge, Bun/Deno, WASI and browser builds run Lean single-threaded, without sockets
or processes (and without files, except on WASI); the rest of Lean works.
## Start here
| I want to build… | Run | Then look at |
| --- | --- | --- |
| A command-line program | `npm create @lasm@latest my-tool` | [examples/hello](https://github.com/Millillion/lasm/blob/main/examples/hello), [examples/wasi-cli](https://github.com/Millillion/lasm/blob/main/examples/wasi-cli) |
| A REST API on Node with an npm framework | `npm create @lasm@latest my-api -- --template hono` (or `express`, `fastify`) | [examples/js-crud](https://github.com/Millillion/lasm/blob/main/examples/js-crud) (Postgres + JWT, Express and Hono) |
| A server in pure Lean (no npm) | `npm create @lasm@latest my-api -- --template fetch` (any target) or `--template std-http` (Node, also native Lean) | [examples/fetch](https://github.com/Millillion/lasm/blob/main/examples/fetch); the `std-http` template |
| A serverless function (Lambda, Vercel, Netlify, Azure, GCF) | `npm create @lasm@latest my-fn -- --template hono --deploy lambda-zip` (or `vercel`, `netlify`, `azure`, `gcf`, `lambda-edge`) | [docs/deploy](https://github.com/Millillion/lasm/blob/main/docs/deploy/README.md) |
| An edge function (Workers, Vercel/Netlify Edge, Deno Deploy, Supabase) | `npm create @lasm@latest my-edge -- --template hono --deploy workers` (or `fetch`) | [examples/edge-pure](https://github.com/Millillion/lasm/blob/main/examples/edge-pure), [docs/EDGE.md](https://github.com/Millillion/lasm/blob/main/docs/EDGE.md) |
| A Fastly, WASI or Spin service | `npm create @lasm@latest my-svc -- --template fetch --deploy fastly` (or `wasi-http`, `spin`, `wasi`) | [examples/fetch](https://github.com/Millillion/lasm/blob/main/examples/fetch), [docs/WASI.md](https://github.com/Millillion/lasm/blob/main/docs/WASI.md) |
| A browser app | `npm create @lasm@latest my-web -- --template web` | [examples/ui](https://github.com/Millillion/lasm/blob/main/examples/ui) (counter, TodoMVC with proofs, feature demo, benchmark) |
| A complete real-world app (API, browser frontend, SQL, auth) with proofs, on Node, Workers or Bun | `cd examples/conduit && npm install && npm run build && npm start` | [examples/conduit](https://github.com/Millillion/lasm/blob/main/examples/conduit), the flagship (below) |
| A full-stack app with a verified API | `npm create @lasm@latest my-app -- --template fullstack` | [templates/fullstack](https://github.com/Millillion/lasm/blob/main/templates/fullstack) |
| To call npm packages or `fetch` from Lean | add `import Lasm.JS` and one `@[js]` line per function | [examples/js-fetch](https://github.com/Millillion/lasm/blob/main/examples/js-fetch), [JS bindings](https://github.com/Millillion/lasm#calling-javascript-and-npm-from-lean) |
| To run on Bun or Deno | `bun create @lasm my-app --template hono` / `deno run -A npm:@lasm/create my-app --template hono` | [docs/BUN\_DENO.md](https://github.com/Millillion/lasm/blob/main/docs/BUN_DENO.md) |
Every example has a README with a one-command run; [examples/README.md](https://github.com/Millillion/lasm/blob/main/examples/README.md)
lists them all.
## Flagship example: Conduit, with 117 proved theorems
[examples/conduit](https://github.com/Millillion/lasm/blob/main/examples/conduit) is [Conduit](https://github.com/gothinkster/realworld),
the RealWorld app (a Medium clone), written entirely in Lean: the REST API, the
server-rendered browser app and the proofs.
- **117 theorems** about the code that actually runs, checked with no `sorry` and
only Lean's standard axioms (`npm run proofs`; [PROOFS.md](https://github.com/Millillion/lasm/blob/main/examples/conduit/PROOFS.md)
lists each one in plain English). They cover authorization (only authors change
their articles and comments), follows and favorites, slugs that never collide,
pagination that never skips or repeats, validation shared by client and server
(the app never sends what the server would reject), JSON round trips and
Markdown link safety. The endpoints are written against a `Store` of functions,
and the proofs run that same code on a model of the tables.
- **What is trusted, not proved:** that each SQL statement does what its model
says, the JSON text layer, concurrency between requests, and Lean, Lasm and the
JavaScript runtime. Conformance to the whole RealWorld spec is tested, not
proved.
- **API:** the official RealWorld API suite passes unmodified (13 of 13 files,
154 requests) on Node (`node:sqlite`), Cloudflare Workers (D1) and Bun
(`bun:sqlite`). Each target has one hand-written `@[js]` binding module.
- **Frontend:** `Lasm.UI` on RealWorld's official templates, with server-side
rendering, hydration and Markdown parsed in Lean. The official Playwright
end-to-end suite passes with no retries on Node with Chromium, Firefox and
WebKit, and on Workers and Bun with Chromium.
All of this runs in CI ([conduit.yml](https://github.com/Millillion/lasm/blob/main/.github/workflows/conduit.yml), run 40615274657,
with `@lasm/cli` 0.3.4).
```
cd examples/conduit
npm install # @lasm/cli, Hurl and Playwright (the official suites' runners)
npm run build && npm start # http://localhost:3000: the app and its API on Node
npm run proofs # check all 117 theorems
npm test # the official API suite (also test:workers, test:bun)
npx playwright install chromium && npm run test:e2e # the official end-to-end suite
npm run build:workers && npx wrangler dev # Cloudflare Workers with local D1
npm run build:bun && npm run start:bun # Bun with bun:sqlite
```
## 60-second start
A single file needs no project. Save this complete program as `Main.lean`:
```
def main : IO Unit := do
IO.println s!"Hello from Lean! 2 + 3 = {2 + 3}"
```
```
npx @lasm/cli Main.lean # builds and runs: Hello from Lean! 2 + 3 = 5
npx @lasm/cli build Main.lean # writes dist/; run it with: node dist/main.mjs
```
The first build on a new machine fetches Lean and the build tools once (about
250–275 MB; 19 s for that first build on the Linux CI runner). Later dev builds of a
one-line change take about 1–2 s.
## Recipes
Each recipe is complete: create, develop, build, deploy. Lasm never installs or
starts a platform's own CLI (`wrangler`, `vercel`, `fastly`, …); you run those.
`npm run dev` is `lasm dev`: it rebuilds about 2 s after each save and restarts
the server, and keeps the last good build running when there is a type error.
**Node server (Hono; also `express`, `fastify`, `std-http`, `fetch`).**
```
npm create @lasm@latest my-api -- --template hono
cd my-api && npm install
npm run dev # http://localhost:3000/hello/Ada
npm run build && npm start # dist/ needs only Node 24+
docker build -t my-api . && docker run -p 8080:8080 my-api # the generated Dockerfile
```
**AWS Lambda / Vercel / Netlify / Azure / Google Cloud Functions.**
```
npm create @lasm@latest my-fn -- --template hono --deploy lambda-zip # or vercel, netlify, azure, gcf, lambda-edge
cd my-fn && npm install
npm run build:lambda #