fix: load static-wado-util via createRequire so Bun can require() it - #133
Open
wayfarer3130 wants to merge 1 commit into
Open
fix: load static-wado-util via createRequire so Bun can require() it#133wayfarer3130 wants to merge 1 commit into
wayfarer3130 wants to merge 1 commit into
Conversation
static-wado-util resolves to lib/index.ts and is ESM, while 48 files in static-wado-creator reach it through a CommonJS require(). lib/index.mjs also imported it as ESM, which pulled it into that module's async graph; Bun 1.3 then rejects every one of those requires with TypeError: require() async module ".../static-wado-util/lib/index.ts" is unsupported. use "await import()" instead. which makes mkdicomweb fail at startup. Nothing in static-wado-util uses top-level await -- the async classification comes purely from the mixed ESM/CJS load order, and requiring the package from a plain CJS entry has always worked. Loading it through createRequire keeps it out of the ESM graph, so all 48 CJS requires resolve synchronously again. static-wado-creator is the only package in the monorepo with this mix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
mkdicomwebfails at startup under Bun 1.3:@radicalimaging/static-wado-utilresolves tolib/index.tsand is"type": "module", while 48 files instatic-wado-creatorreach it through a CommonJSrequire().lib/index.mjsalso imported it as ESM, for a singleuidsbinding. That one import pulls the util into this module's async ESM graph, and Bun then rejects every CJSrequire()of it.Nothing in
static-wado-utiluses top-level await — the async classification comes purely from the mixed ESM/CJS load order. Requiring the package from a plain.cjsentry resolves fine (47 exports), which is what makes the failure specific to the graph rooted atmkdicomweb.mjs.Fix
Load it through
createRequireso it stays out of the ESM graph and the 48 CJS requires resolve synchronously again.Two alternatives were tried and rejected:
bun --preloadof the util first — no effect; Bun classifies it async regardless of load order.requireinprogram/index.jstoawait import()— just moves the error tomkdicomwebConfig.js, and there are 47 more behind it.Scope
static-wado-creatoris the only package in the monorepo with this mix — a scan of all packages for ESM importers and CJS requirers ofstatic-wado-utilreturns only this one.Test
Fails on
master, prints usage and exits 0 with this change.🤖 Generated with Claude Code