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

Usage without polyfills #212

Open
mendeljacks opened this issue Apr 24, 2022 · 6 comments
Open

Usage without polyfills #212

mendeljacks opened this issue Apr 24, 2022 · 6 comments

Comments

@mendeljacks
Copy link

the library cipher-base from browserify-sign is using node js internal module 'stream'
which is not available in the browser.

I have come up with a fix for now which is to patch require('stream') to be require('readable-stream'), but it's not very elegant.

To reproduce:

  • start a vite project with rollup bundler for react
  • import crypto-browserify and try to sign using createSign

Expected:

  • It should work

Actual:

  • Cannot read property call of undefined at require('stream').Transform
@ljharb
Copy link
Member

ljharb commented Apr 24, 2022

The bug is in vite; a non-broken node module bundler provides browser polyfills for node core modules that can work in the browser, including stream.

@mendeljacks
Copy link
Author

I think you are right because I just checked and it works with create react apps webpack config.

If the target audience is browser users who don't have access to node crypto wouldn't it make sense to make the whole package browser compatible out of the box?

@ljharb
Copy link
Member

ljharb commented Apr 25, 2022

It’s already browser compatible - when used with a non-broken bundler. This is how the node ecosystem has worked for over a decade - it’s just that a few bundlers have recently decided to break this tradition and hurt users.

@aanand07
Copy link

aanand07 commented Oct 6, 2022

webpack 4 used to provide polyfills for node core modules by default which is not the case with webpack5.

@secondl1ght
Copy link

secondl1ght commented Jul 28, 2023

For anyone running into this issue I found this package: https://github.com/davidmyersdev/vite-plugin-node-polyfills. I tested it out using createHash from crypto-browserify and it seems to fix the Vite related issues. Maybe the maintainer @ljharb could give his opinion on this package? It looks pretty good from what I can tell but I haven't audited the code, it has over 33K weekly downloads though which is pretty good for a niche package like this one.

@ljharb
Copy link
Member

ljharb commented Jul 28, 2023

@secondl1ght i haven't audited that package either, but if it can fix vite's broken omission of node polyfills, then that seems like the appropriate solution.

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

No branches or pull requests

4 participants