-
Notifications
You must be signed in to change notification settings - Fork 439
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
snarkjs.min.js: Uncaught TypeError: bn.inherits is not a function #317
Comments
To the maintainers: Was able to reproduct this issue in after some investigation I believe it is because the 'bfj' package is getting bundled into the IIFE package. I would suggest to the maintainers to move away from ''bfj' ASAP as it has not been maintained for 3 years, and has been bundled in a way that makes it tricky to rebundle - rollup in particular now bundles it into every bundle as it cannot determine whether bfj's import has any needed side effects. See: webpack-contrib/webpack-bundle-analyzer#383 for more information. For snarkjs, bfj is bundled into main.js even though it is only referenced in cli.js, and this is a problem because bfj depends on In my testing Vite is able to sidestep this problem by bundling the main.cjs to ESM itself, but this remains an issue for anyone not using Vite. I would suggest revisiting the rollup scripts and bundling snarkjs to both esm and cjs, and redefining the "exports" field in I am working on a PR for this issue, but am having trouble with removing bfj from bundles targeting the browser because of the aforementioned side-effect static analysis/code elimination difficulty. Though perhaps not as technically interesting, in my opinion browser-based proving remains the most philosophically necessary of ZKPs in terms of real world use cases where privacy is of utmost importance. Hopefully someone can provide insight/assistance/fixes into this problem. |
Thanks for the investigation @sigmachirality! We aren't going to remove bfj from the CLI because it is needed to not crash on processing JSON too big to fit in memory. I can look into removing it from the browser package though. Regardless, we can always shim inherits using rollup |
I'm not suggesting removing I found a way to remove bfj from the browser build which I pushed as part of #339. What you do is add the following to rollup's config:
This removes |
Would prefer against shimming inherits as it will increase bundle size for code that isn't used in the main bundle. |
Please fix the issue, unable to use snarkjs on the client-side |
Actually, I spent some time deep-diving here and found that the code was just written incorrectly for the browser. I'll have a PR up soon. |
chrome 110.0.5481.100
'snarkjs': '0.6.4'
The text was updated successfully, but these errors were encountered: