Skip to content

fix(bundle): stop writing a Bun polyfill onto globalThis - #1421

Merged
betegon merged 1 commit into
mainfrom
jp/bun-polyfill
Aug 14, 2026
Merged

fix(bundle): stop writing a Bun polyfill onto globalThis#1421
betegon merged 1 commit into
mainfrom
jp/bun-polyfill

Conversation

@JPeer264

Copy link
Copy Markdown
Member

I opened a PR that is using the new CLI instead of the old @sentry/cli@2: getsentry/sentry-javascript#23398

Some E2E tests failed with TypeError: Bun.serve is not a function, because we actually check internally if Bun would be an option. With that polyfill in this CLI this behavior is now forced, without Bun actually being there. Idk why this actually exists, but exporting Bun instead fixes it.


AI description:

The Node polyfills were installed with globalThis.Bun = BunPolyfill, which broke consumers of the npm package in both directions.

Under Bun the global is readonly, so merely importing the package threw "Attempted to assign to readonly property" and took the whole process down. Under Node it left an object named Bun on the global, so unrelated libraries that feature-detect typeof Bun !== "undefined" took their Bun code path and called methods the polyfill does not implement, failing with errors like "Bun.serve is not a function". Both are reachable by anyone who merely depends on this package, since importing it is enough.

The polyfills are already delivered through esbuild's inject, which substitutes unbound identifiers with exported bindings, so exporting Bun gives the bundle the same value lexically without touching the global. The real Bun is preferred when present, so running under Bun keeps the genuine implementation rather than shadowing it.

Verified by importing the built bundle in Node: globalThis.Bun stays undefined, where it previously became an object whose serve and version were missing.

The Node polyfills were installed with `globalThis.Bun = BunPolyfill`, which broke consumers
of the npm package in both directions.

Under Bun the global is readonly, so merely importing the package threw "Attempted to assign
to readonly property" and took the whole process down. Under Node it left an object named
`Bun` on the global, so unrelated libraries that feature-detect `typeof Bun !== "undefined"`
took their Bun code path and called methods the polyfill does not implement, failing with
errors like "Bun.serve is not a function". Both are reachable by anyone who merely depends on
this package, since importing it is enough.

The polyfills are already delivered through esbuild's `inject`, which substitutes unbound
identifiers with exported bindings, so exporting `Bun` gives the bundle the same value
lexically without touching the global. The real Bun is preferred when present, so running
under Bun keeps the genuine implementation rather than shadowing it.

Verified by importing the built bundle in Node: `globalThis.Bun` stays undefined, where it
previously became an object whose `serve` and `version` were missing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@JPeer264 JPeer264 self-assigned this Aug 14, 2026
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cli Ready Ready Preview Aug 14, 2026 9:56am

Request Review

@JPeer264
JPeer264 marked this pull request as ready for review August 14, 2026 10:11
@github-actions github-actions Bot added the risk: low PR risk score: low label Aug 14, 2026
@JPeer264
JPeer264 requested review from BYK and betegon August 14, 2026 10:12
@betegon
betegon merged commit b51e05e into main Aug 14, 2026
30 checks passed
@betegon
betegon deleted the jp/bun-polyfill branch August 14, 2026 14:08
@betegon

betegon commented Aug 14, 2026

Copy link
Copy Markdown
Member

this was some legacy code from when we were running on node. we should remove the polyfills completely

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

Labels

risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants