@metamask/mobile-wallet-protocol-coreassigns its exports at the end of a minified file, a pattern esbuild can’t statically analyze — so named imports likeSessionStorecome backundefined.eciesjsis loaded through a dynamicimport(), and esbuild emits dynamic-import chunks for CommonJS dependencies with only a default export — soPrivateKeycomes backundefined.
Fix via vite.config.js
Two changes are needed: list eciesjs in optimizeDeps.include, and alias @metamask/mobile-wallet-protocol-core to a small ESM shim.
First, create the shim file at src/shims/metamask-mobile-wallet-protocol-core.js:
vite.config.js:
The shim must import the package through its file path (
node_modules/...)
rather than the bare package name — otherwise the alias would rewrite the
shim’s own import. Adjust the relative path to match where your shim file
lives.