fix: unwrap the CommonJS default export when loading eciesjs - #343
Open
imaksp wants to merge 1 commit into
Open
Conversation
imaksp
pushed a commit
to imaksp/connect-monorepo
that referenced
this pull request
Jul 28, 2026
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`eciesjs` publishes CommonJS only, so bundlers shape
`await import('eciesjs')` as `{ default: <module.exports> }` rather than a
namespace carrying the named exports. Destructuring it directly left
`decrypt`, `encrypt`, `PrivateKey` and `PublicKey` undefined, so connecting
over MWP from a bundled browser app threw
`PrivateKey is not a constructor`.
Unwrap `default` when it is present, and cover both module shapes with a
round-trip test.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
imaksp
force-pushed
the
fix/eciesjs-cjs-interop
branch
from
July 28, 2026 08:17
b1395b2 to
d477ef6
Compare
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.
Explanation
createKeyManager()destructures a dynamic import ofeciesjs:eciesjs@0.4.17publishes CommonJS only — nomodulefield, and noimportcondition in itsexportsmap. Bundlers therefore shape that import as{ default: <module.exports> }instead of a namespace carrying the named exports, so all four bindings come backundefinedand connecting over MWP throwsPrivateKey is not a constructor. Node and dev servers synthesize the named exports, which is why this survives CI and Vite dev but breaks a production browser build (hit on Angular 22 / esbuild).This unwraps
defaultwhen it is present, leaving the lazyimport()from #244 intact.The new
KeyManager.test.tsround-trips generate → validate → encrypt → decrypt against realeciesjsin both module shapes; the{ default }case fails onmainand passes here.I audited the other dynamic imports in
connect-multichain: the only remaining third-party CommonJS one is@metamask/mobile-wallet-protocol-corein#createDappClient(), which fails the same way (undefined is not an object (evaluating 'mwpCore.SessionStore.create')). That one is a packaging bug at the source — the package ships an ESM build but declares nomodule/exports— so I've fixed it there rather than working around it here: MetaMask/mobile-wallet-protocol#85.wsis only imported on the non-browser branch, where Node's named-export detection applies.References
Checklist
🤖 Generated with Claude Code