fix(bun): preload node:v8 shim via bunfig to prevent bson crash#420
Merged
Conversation
The isBuildingSnapshot shim added in #419 never took effect. Bun does not guarantee that an earlier ESM side-effect import runs before a later CJS import is evaluated, so `import './utils/bun-compat'` at the top of backend/index.ts still let the mongodb -> bson chain load and crash first. Reproduced against the published 0.4.13 tarball with bson 7.3.1: the shim body never ran before the crash. Load the shim via Bun `preload` instead, which is guaranteed to run before the entry's import graph: - add bunfig.toml with preload = ["./backend/utils/bun-compat.ts"] - ship bunfig.toml via package.json `files` - bin/clopen.ts already spawns the server with cwd = package root, so Bun discovers bunfig.toml and applies the preload Remove the now-ineffective import from backend/index.ts. Also drop the direct bson dependency and the bson override left over from #407/#418: neither can fix the transitive on a global install (overrides are only honored from the root project, not when Clopen is an installed dependency). Verified end to end: a real isolated `bun add -g` that resolves bson 7.3.1, launched via the global bin symlink from an arbitrary cwd, boots instead of crashing. Audited the other entry points too — reset-pat/clear-data and the CLI commands never import mongodb, and no test imports the driver chain.
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.
The isBuildingSnapshot shim added in #419 never took effect. Bun does not guarantee that an earlier ESM side-effect import runs before a later CJS import is evaluated, so
import './utils/bun-compat'at the top of backend/index.ts still let the mongodb -> bson chain load and crash first. Reproduced against the published 0.4.13 tarball with bson 7.3.1: the shim body never ran before the crash.Load the shim via Bun
preloadinstead, which is guaranteed to run before the entry's import graph:filesRemove the now-ineffective import from backend/index.ts. Also drop the direct bson dependency and the bson override left over from #407/#418: neither can fix the transitive on a global install (overrides are only honored from the root project, not when Clopen is an installed dependency).
Verified end to end: a real isolated
bun add -gthat resolves bson 7.3.1, launched via the global bin symlink from an arbitrary cwd, boots instead of crashing. Audited the other entry points too — reset-pat/clear-data and the CLI commands never import mongodb, and no test imports the driver chain.