Skip to main content
File & Module System
JSX
Built-in JSX and TSX support in Bun with configurable transpilation options
Bun supports
react.tsx
How JSX constructs are transformed into vanilla JavaScript internally. The table below lists the possible values of
The function name used to represent JSX constructs. Default value is
The function name used to represent JSX fragments such as
The module from which the component factory function (
index.tsx
Bun will pretty-print the component tree when logged:
react.tsx
.jsx and .tsx files out of the box. Bun’s internal transpiler converts JSX syntax into vanilla JavaScript before execution.
Configuration
Bun reads yourtsconfig.json or jsconfig.json configuration files to determines how to perform the JSX transform internally. To avoid using either of these, the following options can also be defined in bunfig.toml.
The following compiler options are respected.
jsx
How JSX constructs are transformed into vanilla JavaScript internally. The table below lists the possible values of jsx, along with their transpilation of the following simple JSX component:
jsxFactory
Note — Only applicable when
jsx is react."createElement". This is useful for libraries like Preact that use a different function name ("h").
| Compiler options | Transpiled output |
|---|---|
json<br/>{<br/> "jsx": "react",<br/> "jsxFactory": "h"<br/>}<br/> | tsx<br/>import { h } from "react";<br/>h("Box", { width: 5 }, "Hello");<br/> |
jsxFragmentFactory
Note — Only applicable when
jsx is react.<>Hello</>; only applicable when jsx is react. Default value is "Fragment".
| Compiler options | Transpiled output |
|---|---|
json<br/>{<br/> "jsx": "react",<br/> "jsxFactory": "myjsx",<br/> "jsxFragmentFactory": "MyFragment"<br/>}<br/> | tsx<br/>// input<br/><>Hello</>;<br/><br/>// output<br/>import { myjsx, MyFragment } from "react";<br/>myjsx(MyFragment, null, "Hello");<br/> |
jsxImportSource
Note — Only applicable when
jsx is react-jsx or react-jsxdev.createElement, jsx, jsxDEV, etc) will be imported. Default value is "react". This will typically be necessary when using a component library like Preact.
| Compiler options | Transpiled output |
|---|---|
jsonc<br/>{<br/> "jsx": "react",<br/> // jsxImportSource is not defined<br/> // default to "react"<br/>}<br/> | tsx<br/>import { jsx } from "react/jsx-runtime";<br/>jsx("Box", { width: 5, children: "Hello" });<br/> |
jsonc<br/>{<br/> "jsx": "react-jsx",<br/> "jsxImportSource": "preact",<br/>}<br/> | tsx<br/>import { jsx } from "preact/jsx-runtime";<br/>jsx("Box", { width: 5, children: "Hello" });<br/> |
jsonc<br/>{<br/> "jsx": "react-jsxdev",<br/> "jsxImportSource": "preact",<br/>}<br/> | tsx<br/>// /jsx-runtime is automatically appended<br/>import { jsxDEV } from "preact/jsx-dev-runtime";<br/>jsxDEV(<br/> "Box",<br/> { width: 5, children: "Hello" },<br/> undefined,<br/> false,<br/> undefined,<br/> this,<br/>);<br/> |
