fix(cli): use build plugin to redirect morphsdk ESM barrel to CJS - #10956
Merged
Conversation
The createRequire approach from #10955 did not prevent the Bun ESM splitter from generating invalid output. Bun 1.3.14 with `conditions: ["browser"]` resolves @morphllm/morphsdk via the "import" condition (pre-split ESM barrel) even inside createRequire() calls, pulling in 52 chunk-*.js files that cause: SyntaxError: Exported binding 'G9' needs to refer to a top-level declared variable. Fix: add a morphsdkCjsPlugin in script/build.ts using Bun's onResolve API to redirect the module specifier to the absolute path of client.cjs before the ESM splitter is invoked. client.cjs is a self-contained ~2300-line CJS bundle with no chunk-*.js imports. morphsdk.ts is simplified to a plain re-export — the CJS redirection happens at build time, no source-level workaround needed.
chrarnoldus
approved these changes
Jun 5, 2026
catrielmuller
enabled auto-merge
June 5, 2026 19:04
This was referenced Jun 5, 2026
5 tasks
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
…d-plugin fix(cli): use build plugin to redirect morphsdk ESM barrel to CJS
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.
Issue
Follow-up to #10955. The
createRequirefix did not prevent theSyntaxError: Exported binding 'G9' needs to refer to a top-level declared variablefrom occurring. The build-cli job is still failing consistently oncli-linux-x64in https://github.com/Kilo-Org/kilocode/actions/runs/27033311756/job/79791018541.Root cause
Bun 1.3.14 with
conditions: ["browser"]inBun.build()resolves@morphllm/morphsdk/tools/warp-grep/clientvia the"import"condition (the pre-split ESM barrelclient.js) even insidecreateRequire()calls. The surrounding module's ESM context overrides the implicitrequirecondition, so all 52chunk-*.jsside-imports still flow through Bun's ESM splitter, which generates the invalid minified output.Fix
Replace the
createRequireruntime hack with a Bun build plugin (morphsdkCjsPlugin) added inscript/build.ts. The plugin'sonResolvecallback intercepts@morphllm/morphsdk/tools/warp-grep/clientbefore the ESM splitter is invoked and redirects it to the absolute path ofclient.cjs— the self-contained ~2300-line CJS bundle that has nochunk-*.jsimports.morphsdk.tsis simplified to a plain re-export; no source-level workaround is needed because the CJS redirection happens entirely at build time.How to verify
Trigger the publish workflow after merging —
build-cli(all targets, includingcli-linux-x64) should pass without theSyntaxError.Checklist
bun run typecheckfrompackages/opencode/passesbun turbo typecheck(all 17 packages) passesbun run script/check-opencode-annotations.tspasses