Changelog - 2026-10-28
ModuleUtility.load resolves the ES module copy, and preload registers it
Behavior ChangeIn one line. A peer that ships an ES module build and a CommonJS build (bullmq, socket.io-client, the @connectrpc peers) is no longer loaded as a second copy next to the one your own import holds. Ships in 0.4.5.
What changed
ModuleUtility.loadresolves from the project root with theimportcondition of the peer'sexportsmap: the instance your ownimportof the peer gets. A module the project root cannot resolve is imported by name, as before; a registered module still wins.ModuleUtility.preload({ modules })is new: it loads each module withloadand registers it, so the synchronousloadSync(the only path a constructor has) returns the ES module copy afterwards. One line at the entrypoint:await ModuleUtility.preload({ modules: ['bullmq', 'socket.io-client'] }).- The gRPC adapter loads its peers with
load. A registered@connectrpcpeer now satisfies it, as a compiled binary needs. loadSyncis unchanged: it resolves withrequire, so withoutpreload(or the helper'smoduleoption)BullMQHelperandSocketIOClientHelperstill hold the CommonJS copy.
Who is affected
- Code that called
ModuleUtility.loadfor a peer that ships both builds now gets the ES module copy. A CommonJS-only peer still arrives as{ default: <exports> }, as before. - Applications that import
bullmqorsocket.io-clientthemselves and compare classes withinstanceofshould callpreloadonce at the entrypoint, or passmoduleto the helper. Nothing else is needed. - This resolves the "Known dual-copy hazards" paragraph of the 0.4.4 notes.