fix(bundle): stop writing a Bun polyfill onto globalThis - #1421
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
|
this was some legacy code from when we were running on node. we should remove the polyfills completely |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I opened a PR that is using the new CLI instead of the old
@sentry/cli@2: getsentry/sentry-javascript#23398Some E2E tests failed with
TypeError: Bun.serve is not a function, because we actually check internally ifBunwould 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 exportingBuninstead 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
Bunon the global, so unrelated libraries that feature-detecttypeof 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 exportingBungives 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.Bunstays undefined, where it previously became an object whoseserveandversionwere missing.