Skip to content

bun build: leave dev/prod unset for --jsx-* flags - #48337

Open
robobun wants to merge 2 commits into
robobun/49c51871/jsx-flags-leave-dev-prod-unsetfrom
robobun/49c51871/bun-build-jsx-flags-leave-dev-prod-unset
Open

robobun wants to merge 2 commits into
robobun/49c51871/jsx-flags-leave-dev-prod-unsetfrom
robobun/49c51871/bun-build-jsx-flags-leave-dev-prod-unset

Conversation

@robobun

@robobun robobun commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #48152: merge that one first.

Problem

  • With NODE_ENV unset, bun build --jsx-import-source=x imports x/jsx-runtime. Without the flag, and on 1.3.14: x/jsx-dev-runtime. --jsx-runtime, --jsx-factory and --jsx-fragment do the same.
  • src/runtime/cli/Arguments.rs:2005 and :2021 write development: false for each of the four. Since 1.4.0 (jsx: honor tsconfig "react-jsx" vs "react-jsxdev" for the automatic runtime #34422), bun build no longer overwrites that value.

Fix

  • In bun build, each of the four writes None and keeps what a bunfig.toml said. NODE_ENV, --production, bunfig.toml and the tsconfig.json of the working directory then choose.
  • Outside bun build a flag still writes Some(false). bun <file>, bun run and bun test do not change.
  • Verified: test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts (20 new cases, 11 fail on the base branch), test/aot/build-flags.test.ts.

Background

  • JSX compiles to jsxDEV from <source>/jsx-dev-runtime (development) or jsx from <source>/jsx-runtime (production).
  • Leave JSX dev/prod unset for Bun.build() and for a bunfig.toml without jsx #48152 makes api::Jsx.development an Option<bool>. None takes "react-jsx" or "react-jsxdev" from the tsconfig.json, unless NODE_ENV chose.
  • The other choice is one docs line that says a --jsx-* flag means production. It keeps 1.4.x as it is.

Downsides

  • Needs a maintainer's yes. CLI: fixes for bun run, flags, bunfig.toml, .env, --filter, bun init and completions #46007 lists this under "Left out on purpose", and no user reported it.
  • A flagged build that exits 0 on 1.4.4 fails when the import source has only ./jsx-runtime: Could not resolve: "x/jsx-dev-runtime". NODE_ENV=production, --production or tsconfig "react-jsx" keeps it on production.
  • Cost: 3 bytes of code fewer. A flagged bun build beside a tsconfig.json runs 7 more instructions, once.
Notes

The decision

1.4.0 made two changes at the same time. Tsconfig "react-jsx" began to select the production runtime (#34422), and bun build stopped writing its own choice over the development: false that a flag had always carried. The second one was not announced: the list of breaking changes of 1.4 (#28792) has only the first. On the run path the same literal selects jsx-runtime since 1.2.3 (#17013), and this PR does not touch it.

So the question is what a --jsx-* flag means in bun build:

Commands that behave differently now

NODE_ENV and BUN_ENV are not set unless the row says so. "dev" is jsx-dev-runtime, "prod" is jsx-runtime. "Base" is #48152. --jsx-* stands for --jsx-runtime, --jsx-import-source, --jsx-factory or --jsx-fragment.

# Command 1.3.14 1.4.x, main, base This PR
1 bun build --jsx-*, also --no-bundle, --compile, --compile --aot and bun compile (its short form). JSX in a macro that the build runs follows the bundle dev prod dev
1b Row 1 under NODE_ENV=test (a value other than production and development), or with --env=disable prod (1.2.3: dev) prod dev
1c Row 1 when the bundle, or a macro that the build runs, has an import source with only ./jsx-runtime exit 1 exit 0 exit 1, Could not resolve: "x/jsx-dev-runtime" (a macro: Cannot find module 'x/jsx-dev-runtime')
1d Row 1 with React external, and the output run under NODE_ENV=production TypeError: jsxDEV is not a function runs TypeError: jsxDEV is not a function, as the same build without the flag
2 bun build --jsx-* beside bunfig jsx = "react-jsxDEV" dev prod dev
3 bun build --jsx-* when the tsconfig.json with "react-jsx" is not in the working directory: in a subdirectory, in a parent, or nested under a root tsconfig.json that says "react-jsxdev" dev prod dev, as the same build without the flag

What stays: bun build --jsx-* beside tsconfig "react-jsx" in the working directory is prod. In a bundle, NODE_ENV=production or --production is prod, also beside tsconfig "react-jsxdev". With NODE_ENV=development it is dev.

Counts, base against this PR, one process per result: of 80 bun build results (5 tsconfig.json states, 4 NODE_ENV states, bundle and --no-bundle, with and without --jsx-import-source), 14 move, all with the flag and all from prod to dev. 0 of 960 Bun.build() results and 0 of 40 bun <file> results move. The 28 rows of the report that started this: 7 change (02 to 06, 14, 19), all to dev. Rows 13 and 28 stay prod.

Not changed by this PR

  • The run path. A flag still selects jsx-runtime for bun <file>, bun run, -e, a Worker, bun test, BUN_OPTIONS and --compile-exec-argv. An earlier revision moved them too. An import source with only ./jsx-runtime then exits 1 with Cannot find module 'x/jsx-dev-runtime', so they stay. With a yes for the run path, the is_build test at src/runtime/cli/Arguments.rs:1996 goes away.
  • Beside a bunfig.toml, the workers of bun test --parallel load jsx-runtime while the serial run loads jsx-dev-runtime: src/runtime/cli/test/parallel/runner.rs:480 gives each worker a --jsx-runtime flag that nobody typed. 1.4.4 and main do the same. I reported it for a separate fix.
  • --no-bundle takes the value of each file from its tsconfig.json. There a tsconfig.json that says "react-jsxdev" goes before NODE_ENV=production and --production, with and without a flag, as on main. bun build --no-bundle: apply force_node_env to the per-file JSX pragma #38070 is open for that path.
  • NODE_ENV=production bun build with no flag beside a tsconfig.json that does not say "react-jsx" emits jsxDEV (bun build: keep NODE_ENV=production when tsconfig.json does not set "jsx" #38050). With a flag it is prod.
  • --jsx-side-effects with none of the four. It has no effect on 1.4.4 and on main, so such a build is a build with no flag. CLI: fixes for bun run, flags, bunfig.toml, .env, --filter, bun init and completions #46007 makes it work alone.

Other PRs

Measurements

Release builds of the base (1cdba61) and of this branch. The counts are from gdb, llvm-nm and llvm-size.

  • Size: one function differs, arguments::parse, 3 bytes smaller. .text is 108,256,297 bytes in both.
  • Instructions that configure_linker_with_auto_jsx runs itself for bun build --jsx-import-source: 41 to 41 with no tsconfig.json, 64 to 71 beside tsconfig "react-jsx". For bun --jsx-import-source <file>: 64 to 64.

Tests

  • jsx-tsconfig-react-jsx.test.ts: 99 pass on the debug build (83 before the base added 16 cases). 18 rows are bun build with a flag, and 2 rows run a macro. On the base branch 11 of them fail. The others pin what stays.
  • test/aot/build-flags.test.ts: 12 pass. The mine shim tells jsx from jsxDEV. The --jsx-import-source case is built with --compile and with --compile --aot beside --define process.env.NODE_ENV="staging", and prints the development form (row 1b). On the base branch that case fails. A new case pins tsconfig "react-jsx" with a flag as prod for both executables.

Review

Self-reviewed together with #48152: 32 concerns raised for the whole change. For this part the review asked for a PR of its own, because it is the part with a design question, and for rows 1c and 1d to be stated. Both are done. Nothing was rejected.


no test proof · iteration 4 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/aot/build-flags.test.ts

A --jsx-* flag names a factory, a fragment, an import source or a runtime.
Since 1.4.0 it also selected the production runtime in `bun build`, where
1.3.14 and the same build without the flag use the development runtime.

In `bun build` a flag now writes `development: None`, and keeps what a
bunfig.toml said. NODE_ENV, --production, the bunfig.toml and the
tsconfig.json of the working directory then choose. JSX in a macro that the
build runs follows the bundle. Outside `bun build` a flag still writes
`Some(false)`.
@robobun

robobun commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 10:25 PM PT - Nov 9th, 2026

✅ @robobun, your commit 14c37b36a4329f50cb784cabe52466340b0d3f5f passed in Build #139566! 🎉


🧪   To try this PR locally:

bunx bun-pr 48337

That installs a local version of the PR into your bun-48337 executable, so you can run:

bun-48337 --bun

@robobun

robobun commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review at 14c37b3. That commit merges the base (#48152 at 994f466), which added 16 test cases. The code of this PR is the same as at 8d9ddef. It is stacked on #48152, and it waits for a maintainer's choice between this change and a docs line (see "The decision" in the description).

How I reproduced it, with NODE_ENV and BUN_ENV not set:

echo "console.log(<a b='1'>x</a>, <>y</>);" > j.jsx
bun build --external='*' --jsx-import-source=zzsrc j.jsx
# 1.3.14:                      import { jsxDEV, Fragment } from "zzsrc/jsx-dev-runtime"
# 1.4.0 to main, and #48152:   import { jsx, Fragment } from "zzsrc/jsx-runtime"
# this branch:                 import { jsxDEV, Fragment } from "zzsrc/jsx-dev-runtime"

--jsx-runtime=automatic, --jsx-factory=h, --jsx-fragment=F and --no-bundle give the same result. So does a build beside tsconfig "jsx": "react-jsxdev".

Test: bun bd test test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts. On the base branch, 11 of the 20 new cases fail. On this branch, all 99 tests pass.

CI on 14c37b3 (build 139566): 184 jobs passed and none failed. 4 darwin x64 jobs wait for an agent. 6 tests failed one time and passed on a retry. None is a test of this PR.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Additional findings (outside the current diff — GitHub can't attach inline comments there):

  • 🟡 src/runtime/cli/Arguments.rs — Users of bun compile --aot --jsx-import-source=x with no NODE_ENV, no --production and no cwd tsconfig "react-jsx" now get an executable whose JSX calls jsxDEV, and the change ships no test for that entry point. is_build at src/runtime/cli/Arguments.rs:1178 covers CommandTag::CompileCommand, and the AOT route at src/runtime/cli/compile_command/configuration.rs:447 only forces development = false for production; the dismissal traced only --library, which routes to build_command.rs. Fix: pin bun compile (with and without --aot) in the matrix alongside bun build --compile, and confirm the AOT snapshot at bundler/aot/options.rs:243 sees the same resolved value as the bundle. [also at: test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:257 - nit: the bun compile entry point also changes behaviour here but no test exercises it. The is_build gate at src/runtime/cli/Arguments.rs:1178 covers CommandTag::CompileCommand, and bun compile accepts every --jsx-* flag via TRANSPILER_PARAMS_ (src/runtime/cli/Arguments.rs:908), so bun compile --jsx-import-source=x main.jsx moves from x/jsx-runtime to x/jsx-dev-runtime too.]

    Why this was flagged

    Trigger: bun compile --aot --jsx-import-source=x main.jsx (and bun compile when --aot is implied), entering parse() with cmd == CommandTag::CompileCommand, so is_build at src/runtime/cli/Arguments.rs:1178 is true and :2007 writes development: None. CompileCommand::exec_command at src/runtime/cli/compile_command/command.rs:31-41 sends an AOT build to run() and configuration::configure, not to BuildCommand::exec; there src/runtime/cli/compile_command/configuration.rs:447 forces false only under ctx.bundler_options.production, and :433 calls configure_linker() which at src/bundler/transpiler.rs:575 fills from the cwd tsconfig only. The AOT options snapshot at src/bundler/aot/options.rs:243 then freezes forced_jsx_development() into the sema config. On the base the flag carried Some(false) into this path, so the executable called jsx; now it calls jsxDEV, and an import source that ships only ./jsx-runtime fails the compile with Could not resolve: "x/jsx-dev-runtime". Remedy: add bun compile rows and verify the AOT path against the bundle path.

    Verification: src/runtime/cli/Arguments.rs:1178 let is_build = matches!(cmd, CommandTag::BuildCommand | CommandTag::CompileCommand); so :2007 writes None. src/runtime/cli/compile_command/configuration.rs:447-450 only forces development = false under ctx.bundler_options.production, so the base's Some(false) becomes dev for bun compile. test/aot/build-flags.test.ts:312 spawns only [bunExe(), "build", "--compile", ...].

Comment on lines +1995 to +1996
// Outside `bun build`, a `--jsx-*` flag selects the production runtime, as it has since 1.2.3.
let development = |of_bunfig: Option<bool>| if is_build { of_bunfig } else { Some(false) };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Existing bun build --jsx-* users get a different runtime after merging: with no NODE_ENV, --production or tsconfig "react-jsx", JSX now imports &lt;source&gt;/jsx-dev-runtime instead of jsx-runtime. The development closure at Arguments.rs:1996 returns None for BuildCommand/CompileCommand where the base wrote Some(false). This follows from the stated purpose, but it is a silent default flip for a shipped CLI flag: a source with only ./jsx-runtime now fails with Could not resolve: "x/jsx-dev-runtime". Fix: either keep production as the fallback when nothing else chose, or land the flip only with a breaking-change note and an update to the --jsx-* flag docs, which this PR does not touch.

Why this was flagged

A user runs bun build --jsx-import-source=x main.jsx (also with --compile or --no-bundle) with NODE_ENV unset, no --production, and no tsconfig.json "jsx": "react-jsx" in the working directory. On the base branch src/runtime/cli/Arguments.rs:2007 and :2023 wrote development: Some(false), so the bundle imported x/jsx-runtime and called jsx. After the change the closure at src/runtime/cli/Arguments.rs:1996 returns None (or the bunfig value) because is_build (Arguments.rs:1178) is true, so the bundler falls through to the dev runtime and imports x/jsx-dev-runtime with jsxDEV calls. If x exposes only ./jsx-runtime the build now exits 1 with Could not resolve: "x/jsx-dev-runtime"; if the output has React external and is run under NODE_ENV=production it throws TypeError: jsxDEV is not a function where the base build ran. test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:258-264 pins the new dev result for every --jsx-* flag. No docs file is updated and there is no deprecation or note path in the code, so nothing warns the affected users.

Verification: src/runtime/cli/Arguments.rs:1178 is_build = matches!(cmd, BuildCommand | CompileCommand); :1996 let development = |of_bunfig| if is_build { of_bunfig } else { Some(false) }; used at :2007 development(None) and :2023 development(prev.development) where the base wrote Some(false). Pragma::default() development: true (jsx.rs:187), so None yields the dev runtime.

An automated safety screen replaced some characters, such as angle brackets, in the code quoted in this comment with HTML escape codes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This result is the purpose of the PR, and a maintainer has to choose it. The description puts it as one decision with two outcomes: this change, or one docs line that says a --jsx-* flag means production. Rows 1c and 1d of its table are the two failures that you name.

On the docs: docs/bundler/esbuild.mdx:71 already states the rule that this PR gives a flagged build ("If compilerOptions.jsx is "react-jsx", or if NODE_ENV=production, Bun uses the jsx transform. Otherwise, it uses jsxDEV"). No page says that a flag selects the production runtime: docs/snippets/cli/run.mdx:239-253 only says what each flag names. So this PR has no docs text to change. The other outcome is the one that needs a new line. Whether the change goes on a list of breaking changes is part of the same decision.

I leave this thread open for that decision.

Comment thread src/runtime/cli/Arguments.rs Resolved
Comment thread src/runtime/cli/Arguments.rs Resolved
@robobun

robobun commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

On the finding about bun compile: confirmed. bun compile is the short form of bun build --compile --aot, and is_build covers CommandTag::CompileCommand, so the flag change reaches it. I ran release builds of main, of #48152 and of this branch, with no tsconfig.json and NODE_ENV not set. Each executable prints which runtime its JSX called:

Command main, #48152 This branch
bun compile --jsx-import-source=shim m.jsx prod dev
bun compile --aot --jsx-import-source=shim m.jsx prod dev
bun build --compile --aot --jsx-import-source=shim m.jsx prod dev

The three commands agree on each build, so the compiled code gets the value that a bundle gets. Row 1 of the description now names bun compile. test/aot/build-flags.test.ts builds with bun build --compile --aot, which is the same command under its long name. A row with the short name can go in with the next push to this branch.

…obobun/49c51871/bun-build-jsx-flags-leave-dev-prod-unset

# Conflicts:
#	test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no new issues

No new issues were found in this update; 1 finding from earlier reviews is still open above.

Still open from earlier reviews (1):

  • 🔴 src/runtime/cli/Arguments.rs:1996 — Existing bun build --jsx-* users get a different runtime after merging: with no NODE_ENV, --production or tsconfig "rea…

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants