Today's Trends
highInvestigatingBunv1.4.4+38afee6c8, 1.4.4-canary.1+7ca0042d3

Bun Build --no-bundle Rewrites Top-Level This to Exports, Breaking Browser Scripts

  1. Investigating(current)
  2. Trending(upcoming)
  3. Workaround available(upcoming)
  4. Resolved(upcoming)

Executive summary

When using `bun build --no-bundle` for transpile only, Bun replaces every top-level `this` in a non-module file with `exports`, which breaks browser scripts and UMD libraries where top-level `this` refers to the global object. This affects browser targets with or without minification across all formats.

No verified workaround yet

None of the linked reports describe a mitigation. Follow this incident to hear when one appears.

Official fix
Technical root cause

Bun's build transpilation incorrectly replaces top-level `this` references with `exports` even in non-module files.

Evidence

1 report · 1 GitHubShow
  1. [1]
    GitHub First report
    `bun build --no-bundle` rewrites top-level `this` to `exports`, breaking browser scripts and UMD libraries(opens GitHub issue in a new tab)

    What version of Bun is running? 1.4.4+38afee6c8 (also reproduced on 1.4.4-canary.1+7ca0042d3) What platform is your computer? Linux 6.1.0-54-cloud-amd64 x86_64 unknown What steps can reproduce the bug? With --no-bundle (transpile only), bun build replaces every top-level this in a non-module file with exports. This happens for the default --target=browser, with or without --minify, and for every --format. In a classic browser script, top-level this is the global object and there is no exports…

    by trackoor 0upvotes 0comments

Timeline

  1. First report on GitHub issue

    `bun build --no-bundle` rewrites top-level `this` to `exports`, breaking browser scripts and UMD libraries

    Source