Skip to content

fix: replace Wallet class import with inline KeypairWallet for browser compatibility#84

Open
babuClawd wants to merge 1 commit intosolana-developers:mainfrom
babuClawd:fix/wallet-browser-export
Open

fix: replace Wallet class import with inline KeypairWallet for browser compatibility#84
babuClawd wants to merge 1 commit intosolana-developers:mainfrom
babuClawd:fix/wallet-browser-export

Conversation

@babuClawd
Copy link

Problem

Since v2.8.1, using @solana-developers/helpers in browser environments (e.g. with Vite) fails with:

ERROR: No matching export in '@coral-xyz/anchor/dist/browser/index.js' for import 'Wallet'

The Wallet class exported from @coral-xyz/anchor is actually NodeWallet, which is only included in the CJS/Node bundle—not the browser bundle. PR #80 switched from NodeWallet to Wallet, which fixed CJS but broke ESM/browser builds.

Solution

Replace the Wallet class import with a minimal inline KeypairWallet class that implements the same interface (signTransaction, signAllTransactions, publicKey). This is a ~30-line class that:

  • Wraps a Keypair (same as NodeWallet)
  • Implements the Wallet interface expected by AnchorProvider
  • Works in both Node and browser environments
  • Has zero additional dependencies

Why not just use NodeWallet?

NodeWallet uses require('process') and require('fs') in its static local() method, which breaks in browsers. The inline implementation avoids this entirely.

Fixes #81

…er compatibility

The `Wallet` class re-exported from `@coral-xyz/anchor` is actually
`NodeWallet`, which is only available in CJS/Node builds. In browser
environments (e.g. Vite), importing it causes:

  ERROR: No matching export in '@coral-xyz/anchor/dist/browser/index.js'
  for import 'Wallet'

Replace with a minimal inline `KeypairWallet` class that implements the
same `Wallet` interface (signTransaction, signAllTransactions, publicKey).
This makes the helpers package work in both Node and browser environments.

Fixes solana-developers#81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.8.1 No matching export

1 participant