fix(build): disable identifier minification to fix marked crash - #617
Merged
Conversation
Bun's identifier minification creates name collisions in the `marked` library's token walker — `renderInline` (a function) gets the same minified name as an unrelated object, causing `auth status` and other markdown-rendering paths to crash with: TypeError: _4 is not a function. (In '_4(_4.tokens)', '_4' is an instance of Object) The collision was triggered by PR #602 removing ~380 lines of code, which shifted the minifier's naming sequence. Any future code change could re-trigger it since it depends on exact identifier ordering. Fix: use `minify: { whitespace: true, syntax: true, identifiers: false }` instead of `minify: true`. This keeps whitespace removal and syntax transforms (most of the size savings) while avoiding the fragile identifier renaming. Bundle grows from 2.87 MB to 3.64 MB raw, but gzip compression absorbs most of the difference. Made-with: Cursor
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Upgrade
Other
Documentation 📚
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 129 passed | Total: 129 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1359 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.45% 95.43% -0.02%
==========================================
Files 204 204 —
Lines 29739 29739 —
Branches 0 0 —
==========================================
+ Hits 28387 28380 -7
- Misses 1352 1359 +7
- Partials 0 0 —Generated by Codecov Action |
5 tasks
BYK
added a commit
that referenced
this pull request
Apr 1, 2026
… bug Replace Bun.build() with esbuild in the binary build's bundling step (Step 1). Bun's identifier minification has an unfixed collision bug (oven-sh/bun#14585) where minified output produces name collisions across module scopes, causing runtime 'X is not a function' errors. The previous workaround (PR #617) disabled identifier minification entirely, losing ~27% bundle size reduction. esbuild's minifier is more mature and handles identifier mangling correctly. This restores full minification (whitespace + syntax + identifiers) while also fixing a long-standing sourcemap quality issue: Bun's sourcemaps had an empty names array (0 entries), while esbuild produces 27,860 names across 1,006 source files — giving Sentry much better stack trace resolution. Size comparison (esbuild vs Bun.build with identifiers:false): - JS bundle: 2.82 MB vs 3.64 MB (-22%) - Binary gzip: 28.39 MB vs 28.40 MB (negligible) - Sourcemap names: 27,860 vs 0 (massive improvement) Verified: 122 E2E tests pass, auth status renders correctly, debug ID injection works, Bun.build({compile}) accepts esbuild output.
This was referenced Apr 1, 2026
BYK
added a commit
that referenced
this pull request
Apr 1, 2026
… bug (#619) ## Summary - Replace `Bun.build()` with esbuild in the binary build's Step 1 (TS → JS bundling) - Restores full identifier minification that was disabled in #617 - Fixes sourcemap quality: esbuild produces 27,860 names vs Bun's empty array ## Problem Bun's identifier minification has an unfixed collision bug ([oven-sh/bun#14585](oven-sh/bun#14585)) where minified output produces name collisions across module scopes, causing runtime `X is not a function` errors. PR #617 worked around this by disabling identifier minification (`identifiers: false`), but that loses ~22% bundle size reduction and still uses Bun's sourcemaps which have an empty `names` array. The upstream fix ([oven-sh/bun#17930](oven-sh/bun#17930)) was acknowledged as a workaround — the real bug in Bun's renamer/hoisting code was never properly fixed. We still hit collisions on Bun 1.3.11. ## Solution Use esbuild (already a devDependency for the npm bundle) for the binary build's bundling step. The compile step still uses `Bun.build({ compile: true })` since that's the only way to produce native Bun binaries. esbuild's output is standard ESM that `Bun.build({ compile })` accepts without issues. Config: `platform: "node"`, `target: "esnext"`, `format: "esm"`, `external: ["bun:*"]`, `sourcemap: "external"`, `minify: true` ## Size comparison | Metric | PR #617 (identifiers:false) | This PR (esbuild full minify) | |--------|---------------------------|-------------------------------| | JS bundle | 3.64 MB | 2.82 MB (**-22%**) | | Binary (gzip) | ~28.4 MB | ~28.4 MB | | Sourcemap names | 0 (empty!) | 27,860 | | Sourcemap sources | N/A | 1,006 | ## Verification - `auth status` (PR #617 crash scenario): renders markdown correctly - E2E tests: 122 pass, 0 fail, 3 skip - Debug ID injection: works (UUID generated) - `Bun.build({ compile })` accepts esbuild ESM output - Lint: clean ## Changes Single file: `script/build.ts` - Added esbuild import, replaced `Bun.build()` in `bundleJs()` with `esbuild()` - Added `mkdirSync("dist-bin")` since esbuild doesn't auto-create output dirs - Updated JSDoc Made with [OpenCode](https://opencode.ai)
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.
Summary
Fixes the compiled binary crash that affected all commands rendering markdown output (auth status, issue explain, etc.):
Root Cause
Bun's identifier minification assigns short names (
_4,_5, etc.) to all functions/variables. A name collision causedrenderInline(a function inmarkdown.ts) to get the same minified name as an unrelated object. WhenrenderOneInlinecallsrenderInline(token.tokens), the minified code calls_4(_4.tokens)— but_4is the object, not the function.Triggered by PR #602 (716e2ba) which removed ~380 lines of code, shifting the minifier's naming sequence. The bug is in Bun's bundler, not our source code — any future code change could re-trigger it.
Fix
Change
minify: truetominify: { whitespace: true, syntax: true, identifiers: false }inscript/build.ts. This keeps whitespace removal and syntax transforms while avoiding identifier renaming.Size impact: Bundle grows from 2.87 MB to 3.64 MB raw (~27%). Gzip compression absorbs most of the difference since original identifier names compress well.
Bisect
27a9f0f8(PR fix(init): prompt/spinner ordering #610) — works716e2bad(PR feat(skill): add eval framework to measure SKILL.md effectiveness #602) — crashessrc/commands/issue/explain.tstriggers the collision by shifting import orderingTest plan
SENTRY_CLI_BINARY=./dist-bin/sentry-darwin-arm64 bun test --timeout 15000 test/e2e— 122 pass, 0 failSENTRY_AUTH_TOKEN=test ./dist-bin/sentry-darwin-arm64 auth status— renders markdown without crashMade with Cursor