mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 13:06:00 +03:00
[GH-ISSUE #807] Markdown rendering fails when compile with bun and distribute via brew #989
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#989
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sergeyzwezdin on GitHub (Mar 12, 2026).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/807
I'm experiencing a problem with my opentui app. It works perfectly when I run it locally, with markdown rendering functioning as expected. However, when I use bun to compile it and then publish it through homebrew, it fails without any error messages:
I've mentioned this issue in a related post here, but I wanted to bring it to your attention as well.
I spent some time with Claude and it finds the problem in how tree-sitter loads. Check below.
MarkdownRenderable (tree-sitter) broken in Bun compiled binaries — Worker entry point not bundled.
MarkdownRenderable(and any tree-sitter-based syntax highlighting) renders as plain text when the application is distributed as a Bun compiled binary (bun build --compile). It works correctly in dev mode (bun run dev) and appears to work when running the compiled binary from the build directory, but breaks when the binary is installed to a different location (e.g., via Homebrew).Root Cause
TreeSitterClient.startWorker()spawns a Web Worker using:bun build --compiledoes not automatically bundle Web Worker entry points into the compiled binary. Theparser.worker.jsfile is not embedded in the output executable.When the compiled binary runs:
import.meta.dirnameresolves to the binary's directory (e.g.,/opt/homebrew/Cellar/huba/0.0.15/bin/)existsSynccheck forparser.worker.jsnext to the binary → fails (only the binary is installed)parser.worker.tsURL → also doesn't existnew Worker(url)fails with:BuildMessage: ModuleNotFound resolving "/$bunfs/root/parser.worker.ts" (entry point)TreeSitterClientnever initializesMarkdownRenderablereceives no highlights → renders as plain unformatted textWhy It Appears to Work Locally
bun run dev: Runs from source.parser.worker.jsexists innode_modules/@opentui/core/and is resolved normally./$bunfs/root/virtual filesystem paths may still resolve on the same machine where compilation happened, or there's a cached tree-sitter state in~/.local/share/opentui/from previous dev runs.Reproduction
Minimal reproduction of the Bun limitation:
Impact
Any application using
@opentui/core'sMarkdownRenderable,CodeRenderable, orDiffRenderable(anything relying onTreeSitterClient) will silently lose syntax highlighting when distributed as a compiled Bun binary.The failure is silent — no visible error to the user, just plain text output instead of highlighted markdown/code.
Environment
Suggested Solutions
Inline the worker code — Use
new Worker(new Blob([workerSource]))or Bun's inline worker support to avoid the need for a separate file entry point.Main-thread fallback — Detect the compiled binary environment (e.g.,
import.meta.urlcontains/$bunfs/) and fall back to running tree-sitter parsing on the main thread when Worker creation fails.Graceful degradation with clear warning — If the worker fails to spawn, log a visible warning and fall back to unhighlighted rendering, so consumers know what's happening rather than silently degrading.
Document the limitation — At minimum, document that
bun build --compileconsumers need to shipparser.worker.jsalongside their binary and setOTUI_TREE_SITTER_WORKER_PATHenv var.