elements
Start Docs Blog Demos UI Pricing
Elements Manual
  • Getting Started
  • CLI
  • Build
  • Browser
  • Packages
  • TypeScript
  • Elements HTML
  • Assets
  • RPC
  • Router
  • Session
  • Database
  • Migrations
  • LiveTable
  • Channel
  • Jobs
  • Email
  • Payments
  • JSON
  • Async
  • Style
  • UI
  • JSOC
  • Config
  • Tests
  • Logs
  • Deploy
  • Editors
  • Recipes
  • Licenses
  • Issues
  • Changelog
Manual / Build

Build

elements man build

On This Page

  • The Build Loop
  • Verifying UI
  • The Build Server
  • elements start
  • elements build
  • -json
  • The .elements Directory
  • Modules and Emit
  • Build Caching and Versioning
  • Build Transforms
  • Config and Env
  • Peer-to-Peer Deploys
  • Performance
  • Related

A build in Elements means doing everything required to get an application ready for delivery: installing packages, compiling, migrating, testing, and finally releasing the new application to the .elements/release directory. You don't run individual commands to get the app ready. The build server does this automatically as you save files.

This page covers the build server, the output of elements start and elements build, the JSON output of -json, and how the compiler emits, caches, and transforms code. Other steps of the build have their own pages: packages for the installer, tests for the test runner, migrations for the database, typescript for the checker, and deploy for deploying the release.

The Build Loop

Every client connects to the same build server: your terminal, your editor, and any number of agents. The server runs their file saves, build requests, installs, and test runs against one build state, so they do not conflict. A single-file save builds and hot-reloads in milliseconds.

Every file in the project directory is a source. The watcher covers the whole tree apart from node_modules and names that start with a dot, and a change to any file it covers starts a build. That includes files nothing imports: a log an app writes into its own directory, or a data file a script drops next to the code. A build that changes no code reloads nothing, so such a write does not reload the browser, but every line written still starts a build. Write logs and scratch output under .elements/logs, or anywhere outside the project, which the watcher skips.

Verifying UI

A green build means the code compiles, not that the page looks right. When you change a template or a stylesheet, look at the rendered route. With the app running (elements start, serving http://localhost:4000 (opens in a new tab)), screenshot it with the Chromium build already on the machine:

Terminal
# Windows: chrome.exe or msedge.exe. Linux: google-chrome. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \ --headless --disable-gpu --hide-scrollbars \ --window-size=1440,900 --virtual-time-budget=3000 \ --screenshot=/tmp/page.png "http://localhost:4000/your-route"

Then open the image. You do not need Playwright, Puppeteer, chromedriver, or any npm install, and you should not add one.

--window-size sizes the window rather than the viewport, and the platform enforces a minimum window width, so use it for desktop sizes only: at 390,844 macOS lays the page out at 500 and crops the image to 390. Phone widths, clicking, and reading layout back out of the page are all in elements man browser.

The Build Server

The build server is started automatically when you work in a project. It stays running between commands so multiple clients can connect concurrently and see the same build state. Your terminal, the editor LSP, and any agents running in parallel all connect to the same server. State is cached and incremental, so a second elements build -json against an unchanged project answers in microseconds without redoing work.

In development the server idle-shuts-down after a period of inactivity. You can stop it manually with elements kill from inside a project directory, but you shouldn't need to. elements kill stops the whole project: the app, its jobs, the build server, and any elements start, which exits with "Stopped by elements kill." A newer Elements replacing the server after an install is different: elements start reconnects to the new server and the app keeps running.

elements start

Builds and runs your program. Pass a file to run a different program.

The program is one long-lived process, hot reloaded on every save and never restarted. elements start exits when the program exits, with its exit code. An app that cannot bind its port prints what to do and exits with 78, and elements start exits with it. For a script you edit and rerun, use elements run.

The output is dual-mode:

  • When there are build errors, it opens a terminal view that lets you navigate the errors.
  • When build errors are at zero, you see the green OK state and the app's log output.

The user runs it, in a terminal in the project, where they see the build state as they work. An agent runs it in the background only when that fails for the user or they ask (elements man start).

To know whether it is running, read .elements/run. The app writes a file there once it is listening, named for its pid and carrying the url and port. A file whose pid is alive means the app is already serving, so use that url. An empty directory means it is not running: tell the user to type elements start. When another program is already using the port, set PORT in config/env/development.env to a free port before starting the app again.

Everything the program writes to stdout and stderr is logged to .elements/logs/app.jsonl as well as shown in the terminal, and elements logs reads it back (-f follows it). An error a route throws at request time is recorded there, and elements build -json stays green when a route throws: a build covers compile, migrate and test, never what a request does. Any process can read the log, so a subagent can follow the app's output without being the process that started the app. The format: elements man logs.

elements build

elements build shows you the build state. It does not start any user programs. Unlike elements start, there's no application running and no app logs in the output, only the build view. Green OK means the build has no errors. Red Error means the build has errors. The view watches for changes automatically.

Terminal
elements build # build view, watch mode (in a tty) elements build -json # structured json (one-shot, ideal for agents) elements build app/pages/*.ts # shell glob expands to matching files

These commands return the latest build state. They don't trigger a build by themselves; the server is already building in response to file changes.

-json

Every command that reports diagnostics takes -json: one shot, structured, and exit 1 when there are errors. The top-level fields of the JSON are the same for every command.

Output
{ "path": "/abs/path/to/project", "ok": false, "errorCount": 1, "warningCount": 0, "message": "The build has 1 error.", "buildGen": 42, "buildRanAt": "2026-08-21T09:15:06.612-07:00", "elapsedSeconds": 0.259, "diagnostics": [ { "code": 200012, "level": "error", "message": "Test equality failed. Got: 1, Want: 2.", "path": "app/pages/home/test.ts", "loc": { "start": 220, "finish": 231, "line": 13, "column": 5 } } ] }

Read ok for the outcome; message says the same thing as a sentence. Diagnostic paths are relative to path (files outside the project stay absolute), and loc.line/loc.column are 1-based. Source text is not included: read the file when you want the code around a diagnostic.

The answer always reflects what is on disk. Write a file and ask in the same command: the query waits for your edit to build rather than returning the state from before it. buildGen changes only when a build runs, so comparing it across two calls says whether anything rebuilt; buildRanAt is when that build finished. started, finished, and elapsedSeconds time the request, not the build.

elements test -json has the same top-level fields plus a tests object:

Test output
"tests": { "total": 3, "passed": 2, "failed": 1, "notRun": 0, "files": [ { "path": "app/pages/home/test.ts", "status": "fail", "tests": [ { "description": "home", "status": "fail", "assertions": 0, "children": [ { "description": "renders", "status": "pass", "assertions": 2 }, { "description": "counts", "status": "fail", "assertions": 1 } ] } ] } ] }

status is pass, fail, or not-run, and the counts are leaf tests, so total is passed + failed + notRun. notRun counts tests that have not run yet or are skipped; they are not passes. While the build has an error, every file and test is fail with "reason": "build", whatever its last run said; the entry has no reason when the status is the test's own. Fix the build and the next answer shows the real results. assertions is how many assert() and equal() calls a test's own body made, passing or failing; a nested test counts its own, and errorf() and fatalf() are not counted. A test that ran with assertions: 0 checked nothing. The tree says which tests ran, not why one failed: a failing assertion is a diagnostic in diagnostics, with a breadcrumbs trail naming the test.

The .elements Directory

.elements/ is the project's working directory, managed by the build server. Don't modify it by hand. .elements/logs/ holds the logs for the program, its jobs, and the build server.

  • .elements/logs/app.jsonl is everything the running program wrote, one log record per line. Read it with elements logs; see elements man logs.
  • .elements/run/ holds one file per running server, named for its pid, carrying the url and port it is serving on. The app writes its file once it is listening and removes the file when it stops. A file whose pid is no longer running was left by a crash, and readers skip it.
  • .elements/build/ is the scratch directory for the in-progress build.
  • .elements/release/ is the atomic release directory. In development it's a symlink to the current build. In production it's updated in one shot, when a new build is fully ready, so a running service never reads a mix of old and new files during a deploy.

Modules and Emit

Elements emits a release graph: every file the program reaches through its imports. It has four properties:

  1. The release contains every reachable program file. Elements walks the import graph from the program entry points and writes every file the program actually reaches, including reachable node modules. A file the program can't reach is not written to the release.

  2. Build-time resolution equals runtime resolution. Elements rewrites every package import path to point directly at the resolved file, rather than relying on Node.js resolution semantics at runtime. If a path resolved to a particular file at build time, that's the exact file you'll resolve to at runtime.

  3. CJS at runtime on both targets. Every module is transformed to CJS, on browser and server. Two reasons. First, hot reloading Node.js requires CJS. Second, the browser supports ESM, but not every npm package is written in ESM, and converting ESM to CJS is the safe direction. Converting CJS to ESM safely isn't always possible. CJS at runtime keeps both targets compatible with every package, and keeps hot reload working everywhere.

  4. Browser modules are linked via a small loader. Each HTML page automatically embeds a tiny module loader. The loader lets modules require other modules across different HTTP assets. They don't have to be bundled into one file. Each browser file name carries a content hash, and Elements tells the browser to cache those URLs forever. Cache invalidation is just a URL change.

Benefits of the Release Graph

  • Hot reloading gives near-instant feedback from code change to running app.
  • Tests run near-instantly.
  • The browser's require system works across disparate hashed-URL assets, so a small code change invalidates a small number of URLs and the rest stay cached at the edge.

Build Caching and Versioning

Elements gives every source a version, derived from its content plus the versions of everything it depends on. Type checking, compilation, and emit each consult that version before doing any work. If the version hasn't changed since the last run, the cached result is reused. If it has, the affected node and its dependents recompute and nothing else does.

Every stage of the build does work only for what changed: watching, scanning, parsing, binding, type checking, emit, hot reload, and the protocols between clients and the build server. A change deep in the graph rebuilds exactly the affected subgraph, and nothing else.

Build Transforms

A small set of compiler transforms run during the build to make code easier to write:

  • RPC. Functions marked @rpc are callable from the browser. The compiler securely rewrites browser call sites into network requests and strips the function body out of the browser bundle.
  • Sync-style async. Calls to the functions that support it (sql, tx, channel.notify, LiveTable mutations, RPC calls and the rest listed in man async) are automatically converted to await calls, and the surrounding function declaration becomes async. The conversion propagates up the call stack.
  • Server-only stripping. Server-only code is removed from the browser bundle automatically. You do not mark anything: the compiler follows the call graph from browser code. A call to a server-only function (sql, tx, session.login) from browser-reachable code is a compile error at the call site, so a query or a secret cannot reach the browser by accident.
  • Module-level tree shaking. Unused exports are dropped from the output, file by file. Combined with content-hashed URLs, this keeps the code sent to the browser small and cache invalidation precise.

Config and Env

Elements evaluates environment variables at build time. Every env reference resolves against the active .env file as part of the build, so missing variables, typos, and wrong-typed values fail the build before they reach a release. Because the values are resolved at build time, the compiler can constant-fold comparisons against them. For example:

Example
if (process.env.ENV === "production") { // production-only code } else { // dev-only code }

The compiler folds the comparison against the actual value of ENV and drops the unreachable branch from the output entirely.

JSOC config files are also resolved at build time. Every env(...) call inside config.jsoc resolves at build time, and the compiler emits the result as a plain JSON file. At runtime your app reads that JSON directly. There's no JSOC parsing and no env lookup at runtime.

Full config syntax: elements man config.

Peer-to-Peer Deploys

The build system runs peer-to-peer on deploy. Your local build server connects over SSH to the build server on every machine in the environment, all of them at once. Each pair diffs its source graphs, transfers only what changed, and the machine does a minimal incremental build against its own cache, so a small change deploys as a small transfer and a small build.

Performance

A single-file save builds and hot-reloads in milliseconds. Several factors compound:

  • Graph versioning means most work is cached. A second build that touches no sources returns instantly.
  • The TypeScript checker runs in the same process as the build, against the same graph.
  • Hot reload patches the running process or browser at the smallest level required by the change.
  • Peer-to-peer deploy reuses the same versioning and caching, so production releases are as incremental as development builds.

Related

  • packages: the installer. Part of the build, fast, node module compatible, and local packages that are watched like source.
  • tests: the test runner. Concurrent workers, rerun only on change, each test in a transaction, and no release until every test passes.
  • typescript: the checker, compiled into the binary, and the Elements languages built on it.
  • migrations: SQL files applied as you save.
  • deploy: the same build system, peer to peer, to the machines you own.
Prev CLINext Browser
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026