Skip to main content
Bun natively supports JSX and TSX syntax without requiring a separate build step. JSX is transformed to JavaScript function calls at runtime.

Quick Start

Run JSX/TSX files directly:
Run JSX
No Babel, no webpack needed.

JSX Transformation

Bun transforms JSX elements into function calls:
JSX input
Output (classic runtime)
Output (automatic runtime)

JSX Runtimes

Bun supports multiple JSX transformation modes:

Classic Runtime (React.createElement)

Default behavior for React:
Classic runtime
Transformed to:
Configuration:
tsconfig.json

Automatic Runtime (react/jsx-runtime)

Modern React 17+ runtime:
Automatic runtime
Transformed to:
Configuration:
tsconfig.json

Development Runtime

Includes debug information:
tsconfig.json
Adds __source and __self props for better debugging.

Preserve

Leaves JSX unchanged (for further processing):
tsconfig.json

Configuration

tsconfig.json

Configure JSX behavior:
tsconfig.json

Runtime Configuration

Override JSX settings programmatically:
Runtime JSX config

Custom JSX Factories

Use JSX with any framework:

Preact

tsconfig.json
Preact JSX

Custom h() function

tsconfig.json
Custom h() function

Vue JSX

tsconfig.json

Solid.js

tsconfig.json

JSX Features

Children

JSX children

Fragments

Fragments

Spread Attributes

Spread attributes

Conditional Rendering

Conditional rendering

Event Handlers

Event handlers

Ref Attributes

Refs

Namespaced Attributes

Namespaced attributes

TypeScript + JSX (TSX)

Combine TypeScript types with JSX:
TypeScript JSX

Generic Components

Generic components

Type Assertions in JSX

Type assertions

JSX Performance

Automatic Import Optimization

Bun automatically imports JSX functions only when needed:
Automatic imports
No imports added if no JSX in file.

Static Children Optimization

Static optimization

React Fast Refresh

Bun supports React Fast Refresh for hot reloading:
React Fast Refresh
Enable Fast Refresh:
Implementation: src/runtime.zig:147 - React Fast Refresh feature flag

JSX Outside React

Use JSX with any virtual DOM library:

Minimal JSX Runtime

Custom JSX runtime
tsconfig.json

DOM JSX

Create real DOM elements:
DOM JSX

Debugging JSX

Inspecting Transformed Code

View transpiled output

Source Maps

Bun generates inline source maps for JSX:
Original source
Debugger shows original JSX, not transformed JavaScript.

JSX Debug Mode

Debug JSX transform

Implementation

JSX transformation implementation:
  • Parser: src/js_parser.zig - Parses JSX syntax
  • Printer: src/js_printer.zig - Generates function calls
  • Runtime: src/runtime.zig:159 - Auto-import JSX configuration
  • Options: src/options.zig - JSX pragma configuration

Feature Flags

Runtime JSX configuration (src/runtime.zig:159)

Common Patterns

Conditional Class Names

Conditional classes

Render Props

Render props

Component Composition

Component composition

Troubleshooting

React is not defined

Error
Solution: Use automatic runtime or import React:
tsconfig.json
Or:

JSX not transforming

Ensure file has .jsx or .tsx extension:

Custom pragma not working

Check tsconfig.json is in project root and properly formatted.