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

Tong/416 do not rollup cosmo #70

Merged
merged 2 commits into from
Nov 30, 2024
Merged

Tong/416 do not rollup cosmo #70

merged 2 commits into from
Nov 30, 2024

Conversation

supertong
Copy link
Contributor

This PR reverts #68 and do not rollup @cosmjs/stargate in the bundler.

Causes

There are a few things playing together that caused the problem:

  1. During next build, NextJs will try to pre-render the page and that's what the "collect page data" is doing. The code will be excuted in NodeJs runtime instead of a proper browser during the pre-render phase.
  2. The rollup function from Vite will mangle the original code of libsodium-sumo which is a library dependency of @cosmjs/crypto. As a result, the crypto library wasn't properly imported and could not be executed in NodeJs.

How to narrow down the error?

Unfortunately, NextJs doesn't surface the error very well during pre-render. The actual error is

TypeError: Z.randomBytes is not a function
    at ht (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:12694:52)
    at 36836 (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:12697:37)
    at eval (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:12751:45)
    at a (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:12752:31)
    at wasm://wasm/000c792a:wasm-function[232]:0x1e7cd
    at wasm://wasm/000c792a:wasm-function[449]:0x28578
    at _e (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:12877:27)
    at eval (webpack-internal:///(ssr)/../bbn-wallet-connect/dist/index.es.js:13566:38)

The next dev command does surface the error but doesn't give much information on where to look at. This is not the fault of next dev though, it's the libsodium-sumo library actually throwing a string instead of a proper error like

throw "No secure random number generator found"

That caused some trouble to locate the actual error but with some grep|ack, it's not to hard to narrow down where it's thrown. The TTT sumo 2 at the end is how I locate the message.
image

Solution:
Exclude @cosmjs/stargate from rollup so that it doesn't get mangled by Vite.

@totraev totraev merged commit 651f91f into main Nov 30, 2024
1 check passed
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.

2 participants