Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet-adapter-torus uses require('stream') and require('crypto') #584

Closed
stijlist opened this issue Oct 5, 2022 · 4 comments
Closed

wallet-adapter-torus uses require('stream') and require('crypto') #584

stijlist opened this issue Oct 5, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@stijlist
Copy link

stijlist commented Oct 5, 2022

Describe the bug
Bundling @solana/wallet-adapter-wallets fails because wallet-adapter-torus references require('stream') and require('crypto').

I'll file an issue against torusresearch/solana-embed - just wanted to mention the issue here as well.

To Reproduce
Steps to reproduce the behavior:

  1. Download the files in this gist: https://gist.github.com/stijlist/174b3b3c8bc6e4d009826c8a13a7e6612.
  2. Run esbuild index.tsx --bundle --sourcemap --outfile=src/assets/index.js
~/mkt:minimal-repro-wallet-adapter-torus: (1)> esbuild index.tsx --bundle --outdir=.
✘ [ERROR] Could not resolve "stream"

    node_modules/cipher-base/index.js:2:24:
      2 │ var Transform = require('stream').Transform
        ╵                         ~~~~~~~~

  The package "stream" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "--platform=node" to do that, which will remove this error.

✘ [ERROR] Could not resolve "crypto"

    node_modules/@toruslabs/eccrypto/browser.js:9:25:
      9 │ var nodeCrypto = require('crypto');
        ╵                          ~~~~~~~~

  The package "crypto" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "--platform=node" to do that, which will remove this error.

2 errors

Expected behavior
wallet-adapter-torus includes dependencies to polyfill stream and crypto.

@jordaaash
Copy link
Collaborator

wallet-adapter-torus includes dependencies to polyfill stream and crypto.

But it does:
https://github.com/solana-labs/wallet-adapter/blob/e56613051e494ba6cf85c1dfac4415a09e20b376/packages/wallets/torus/package.json#L35-L56

Wallet Adapter doesn't bundle anything though. Bundling (and accordingly, polyfilling) is left to applications.

Here's an example of how Create React App can be configured to do this:
https://github.com/solana-labs/wallet-adapter/blob/e56613051e494ba6cf85c1dfac4415a09e20b376/packages/starter/create-react-app-starter/config-overrides.js#L31-L36

It sounds like, arguably, @toruslabs packages should do their own bundling if they require polyfills.

@ieow
Copy link
Contributor

ieow commented Oct 11, 2022

I think this is the same issue as the #554
you could refer this https://web3auth.io/docs/troubleshooting/webpack-issues to troubleshoot

here is my repo with cra+wallet-adapter-torus, you can refer this as well
https://github.com/ieow/cra-wallet-adpater

@chungquantin
Copy link

You can refer to this boilerplate for configuration using react-app-wired and config-overrides.js: https://github.com/snowflake-so/safe-app-boilerplate-js

@jordaaash jordaaash added the bug Something isn't working label Oct 20, 2022
@steveluscher
Copy link
Collaborator

It sounds like it's up to Torus to bundle polyfills or eliminate the need for them from their browser-bound code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants