-
Notifications
You must be signed in to change notification settings - Fork 13
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
Buffer detection #7
Comments
We can't use the `**` operator as right now it gets transpiled to `Math.pow` which only takes Numbers. Similarly, trying to avoid referencing node globals to get a `Buffer` instance causes similar problems now that bundlers don't tend to come with node polyfills any more. Swaps the use of `**` for the BigInt literal result of the calculation and uses the `Buffer` module to ensure compatibility. Fixes #7 Fixes #8 Please publish with a `main` field to also fix #9.
What I don't understand about this is that I test this, in the package scripts and in GitHub Actions with Webpack 4 with standard polyfill settings, and I had a user contribute support for 5 without any polyfills. It's not supposed to break with Webpack of all the bundlers! I've gone to a lot of effort here to avoid triggering pulling in the polyfills at all for Webpack 4 even when they're available. |
A fix attempt was made in #11 but this is still broken under certain conditions, notably bundling with webpack 5.
|
Swapping out |
`global` is not defined in browsers. Use `globalThis` instead. Fixes #7
`global` is not defined in browsers. Use `globalThis` instead. Fixes #7
I'm trying to build this module with webpack in js-ipfs/examples/browser-webpack and the Buffer detection doesn't work:
It's good to use buffer because
Buffer.allocUnsafe(size)
is significantly faster thannew Uint8Array(size)
, but it's bad to use node globals.Solutions:
The text was updated successfully, but these errors were encountered: