Getting started
This page creates a browser application with Reze, TypeScript, and Vite. You write a counter component, mount it with render, and run the development server and the production build. The last section lists the setup errors you are most likely to see and their fixes.
Requirements
- Node.js
^20.19.0or>=22.12.0, the range that Vite 8 supports. - pnpm.
Create the project
Run these commands to create the project folder and install its packages:
mkdir my-reze-app
cd my-reze-app
pnpm init
pnpm add reze-js
pnpm add -D @rezejs/vite-plugin vite typescript
mkdir src
The reze-js package provides render at runtime, and it declares the compiler syntax (signal, computed) for TypeScript. @rezejs/vite-plugin compiles Reze code in Vite. typescript provides the tsc command used for type checking.
In package.json, add "type": "module" and the scripts below. Keep the other fields that pnpm init and pnpm add wrote. Vite loads vite.config.ts as an ES module, and the Vite plugin is ESM only, so the build fails without this field.
{
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "tsc --noEmit"
}
}
Configure Vite
In vite.config.ts at the project root, add the Reze plugin to plugins:
import reze from "@rezejs/vite-plugin";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [reze()],
});
The plugin compiles the JSX and compiler syntax in your modules. TypeScript's JSX settings do not compile signal or computed, so the plugin is required.
Configure TypeScript
Create tsconfig.json at the project root:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "preserve",
"jsxImportSource": "reze-js",
"strict": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"noEmit": true,
"types": ["vite/client"]
},
"include": ["src", "vite.config.ts"]
}
Three of these options are required for Reze code to type-check:
jsx: "preserve"leaves JSX for the Reze compiler. Without it, TypeScript reportsTS17004.jsxImportSource: "reze-js"selects the JSX types that Reze provides. Without it, TypeScript reportsTS7026for each JSX element.types: ["vite/client"]declaresimport.meta.envand side-effect imports of CSS files. Without it, TypeScript reportsTS2339orTS2882.
Removing moduleResolution, strict, or verbatimModuleSyntax did not change the diagnostics for the samples in this guide. The remaining options are the settings this guide uses.
Files that contain JSX must use the .tsx extension. A .ts file with JSX fails to parse with PARSE_ERROR.
When an editor auto-imports the JSX type, TypeScript suggests reze-js/jsx-runtime first. To
import it from reze-js instead, exclude the runtime modules from auto-imports. In VS Code, add
this to .vscode/settings.json:
{
"typescript.preferences.autoImportFileExcludePatterns": ["**/jsx-runtime*", "**/jsx-dev-runtime*"]
}
In Zed, add this to settings.json:
{
"lsp": {
"vtsls": {
"settings": {
"typescript": {
"preferences": {
"autoImportFileExcludePatterns": ["**/jsx-runtime*", "**/jsx-dev-runtime*"]
}
}
}
}
}
}
Create the document
Create src/document.tsx. It is the HTML page around the app: it holds the element that render mounts into and the script that loads the entry module:
import type { JSX } from "reze-js";
export default function Document(props: { children: JSX.Element }) {
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Reze app</title>
</head>
<body>
<div id="app">{props.children}</div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
);
}
The plugin compiles the document into the HTML entry and never reads index.html. A project that still has index.html at the root fails with a message that asks you to move its tags into the document. The id must match the id passed to getElementById in src/main.tsx, and the script path starts at the project root. The document covers the shape and the components it can inline.
Write the Counter component
Create src/Counter.tsx with a component that takes a step prop:
import { computed, signal } from "reze-js";
export function Counter(props: { step: number }) {
let count = signal(0);
const doubled = computed(count * 2);
return (
<section>
<p>
Count: <output>{count}</output>
</p>
<p>Doubled: {doubled}</p>
<button onClick={() => (count -= props.step)}>Decrease</button>
<button onClick={() => (count = 0)} disabled={count === 0}>
Reset
</button>
<button onClick={() => (count += props.step)}>Increase</button>
</section>
);
}
signal and computed are compiler syntax. The compiler lowers them to reactive state, and reze-js exports no runtime implementation for them. Assignments to count, such as count -= props.step, update every binding that reads count.
computed takes the expression itself. Write computed(count * 2), not an arrow function. For the update rules, see Reactivity.
Mount the app with render
Create src/main.tsx, which mounts Counter into the app element:
import { render } from "reze-js";
import { Counter } from "./Counter";
render(() => <Counter step={1} />, document.getElementById("app")!);
render(code, element) takes a function that returns JSX and the element to mount into. Before it inserts the result, render clears the element's existing content. It returns a function that disposes the app and empties the element.
getElementById returns null when no element has the given id. In that case render throws, and the page stays blank. See Troubleshoot setup.
Run the app
Start the development server
Run the dev server:
pnpm dev
Open the URL that Vite prints, which is http://localhost:5173/ by default. The page shows Count: 0 and Doubled: 0, and Reset is disabled. Increase changes the count to 1 and the doubled value to 2. Reset returns both to 0. Decrease has no lower bound, so the count can go negative: after Increase and then two Decrease clicks, the page shows Count: -1 and Doubled: -2.
Check, build, and preview the app
Run these commands in order:
pnpm check
pnpm build
pnpm preview
pnpm checkrunstsc --noEmit. It reports type errors and writes no files.pnpm buildwrites the production app todist/. A Reze compile error stops the build and prints the diagnostic.pnpm previewservesdist/on your machine so you can check the production build. The page behaves the same as in the dev server.
Troubleshoot setup
Match the message you see to a row in the table:
| Message | Cause | Fix |
|---|---|---|
Unexpected JSX expression during pnpm build | The reze() plugin is missing from plugins, so Vite parses JSX without the Reze compiler. | Add reze() to plugins in vite.config.ts. |
PARSE_ERROR (reported by the Reze plugin) in a file with a .ts extension | The file contains JSX but has the .ts extension. | Rename the file to .tsx. |
"signal" is not exported by ... reze-js (MISSING_EXPORT) during the build, or the browser error "does not provide an export named 'signal'" | The plugin did not compile the file. At runtime, reze-js exports only render. | Add reze() to plugins in vite.config.ts. |
SIGNAL_DEFAULT_EXPORT | A file uses export default with a signal, such as export default count. | Export the signal by name, as in export let count = signal(0), or export a function that reads it. |
Cannot set properties of null (setting 'textContent') in the browser console | document.getElementById("app") returned null, so no element in src/document.tsx has that id. | Make the id in src/document.tsx match the id in src/main.tsx. |
| Blank page, and a 404 response for the script in the browser network log | The src in src/document.tsx does not match a file in the project. | Set the script src to /src/main.tsx, and check that the file exists. |
[reze] a client-only app renders its page from src/document.tsx and never reads index.html during pnpm build | The project still has an index.html next to src/document.tsx. | Move the tags from index.html into src/document.tsx, then delete index.html. |
TS2339 for import.meta.env, or TS2882 for a CSS import | The types array in tsconfig.json does not include vite/client. | Add "types": ["vite/client"]. |
TS17004: Cannot use JSX unless the '--jsx' flag is provided | jsx is missing from tsconfig.json. | Add "jsx": "preserve". |
TS7026: JSX element implicitly has type 'any' | jsxImportSource is missing from tsconfig.json. | Add "jsxImportSource": "reze-js". |
"This package is ESM only but it was tried to load by require" while Vite loads vite.config.ts | package.json does not set "type": "module". | Add "type": "module" to package.json. |
Related pages
- Reactivity:
signal,computed,store, andaction. - Components and JSX: props, children, and supported JSX.
- Lifecycle and cleanup: effects, scheduling, and cleanup.
- Routing: file routes and layouts for apps with several screens.
- The compiler: what the compiler lowers and where module boundaries apply.
- Vite plugin: plugin options.