Skip to content

dual-copy problem with browser exports #1339

@marcelosalloum

Description

@marcelosalloum

Describe the bug
@stellar/js-stellar-sdk has a a dual-copy problem within the same version:

  1. 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 calls import { TransactionBuilder } from "@stellar/stellar-sdk" in a browser build, esbuild resolves the "browser" export condition and pulls in this bundle. The Transaction class from this embedded copy is what TransactionBuilder.build() returns.
  2. Copy B — The "./rpc" subpath export has no "browser" condition — it always resolves to ./lib/rpc/index.js. That CJS file does require("@stellar/stellar-base"), which resolves to the standalone @stellar/stellar-base@14.0.4 package in node_modules. This is a separate module instance with its own Transaction class.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog (Not Ready)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions