-
Notifications
You must be signed in to change notification settings - Fork 343
Description
Describe the bug
@stellar/js-stellar-sdk has a a dual-copy problem within the same version:
- Copy A — The browser bundle (
dist/stellar-sdk.min.js) is a self-contained UMD webpack bundle. It inlines@stellar/stellar-base@14.0.4's own browser dist inside itself. When one callsimport { TransactionBuilder } from "@stellar/stellar-sdk"in a browser build,esbuildresolves the "browser" export condition and pulls in this bundle. TheTransactionclass from this embedded copy is whatTransactionBuilder.build()returns. - Copy B — The
"./rpc"subpath export has no "browser" condition — it always resolves to./lib/rpc/index.js. That CJS file doesrequire("@stellar/stellar-base"), which resolves to the standalone@stellar/stellar-base@14.0.4package in node_modules. This is a separate module instance with its ownTransactionclass.
This resulted in an error being thrown by a mismatched instance (instanceof): Copy A's TransactionBuilder.build() returns a Transaction from the browser-embedded stellar-base, then Copy B's assembleTransaction() (from ./lib/rpc/) calls TransactionBuilder.cloneFrom() which checks instanceof against the standalone stellar-base's Transaction. Same version, same code, but two distinct module instances — instanceof returns false, and an error is thrown.
Suggested solution
This seems to be a bug in @stellar/stellar-sdk's export map. The ./rpc and /contract subpath exports should either:
- Have their own "browser" condition pointing into the UMD bundle; or
- The root
.export should not have a "browser" condition that diverges from the lib/ tree
What version are you on?
14.5.0
Expected behavior
instanceof should succeed