fix(browse): externalize @ngrok/ngrok in node server build#947
Open
exabird wants to merge 1 commit intogarrytan:mainfrom
Open
fix(browse): externalize @ngrok/ngrok in node server build#947exabird wants to merge 1 commit intogarrytan:mainfrom
exabird wants to merge 1 commit intogarrytan:mainfrom
Conversation
The node-compatible server bundle build fails with:
error: cannot write multiple output files without an output directory
Root cause: `@ngrok/ngrok` (added for /pair-agent tunneling) ships two
native .node binaries (darwin-universal and darwin-arm64, ~28 MB total)
that bun tries to emit as assets alongside the JS bundle. Since
`--outfile` can only produce a single file, bun refuses.
`@ngrok/ngrok` is already loaded dynamically at runtime via
`await import('@ngrok/ngrok')` in server.ts, so externalizing it is
safe — the resolver finds it from node_modules at runtime.
Tested on bun 1.3.11 / darwin-arm64: server-node.mjs now builds
successfully (307 KB, 23 modules).
|
niubility |
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.
Problem
Running
./setup(orbrowse/scripts/build-node-server.shdirectly) fails with:Reproduced on: bun
1.3.11, macOS arm64, gstack0.16.2.0.Root cause
@ngrok/ngrokwas added (I believe in0.16.xfor/pair-agenttunneling). That package ships two native.nodebinaries as assets:ngrok.darwin-universal-*.node(~19 MB)ngrok.darwin-arm64-*.node(~9 MB)When bun bundles
server.ts, it statically analyzes@ngrok/ngrok(even though the actual import is dynamic viaawait import('@ngrok/ngrok')) and tries to emit those.nodefiles as additional outputs next toserver-node.mjs. Since--outfilecan only produce a single file, bun aborts with the "cannot write multiple output files without an output directory" error.Fix
Add
--external "@ngrok/ngrok"to thebun buildcommand inbrowse/scripts/build-node-server.sh.This is safe because
@ngrok/ngrokis already loaded dynamically at runtime inserver.ts:At runtime, Node resolves
@ngrok/ngrokfromnode_modules/just like the other runtime-loaded externals (playwright,playwright-core,diff).Verification
Both
server-node.mjs(307 KB) andbun-polyfill.cjsare generated correctly.Notes
import()on an opt-in code path (/tunnel/start), externalizing it should not break any eager initialization.