You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
The file itself gets pulled in through bcoin/lib/protocol/networks.js and possibly others.
bcrypto uses BigInt, which some browsers do not support. The library provides an alternative implementation of its big number backend intended for browsers. Apparently, their first approach is to mapping each file to its browser-version in package.json. webpack/cra seems not to respect this.
Secondly, the file bcrypto/lib/bn.js is supposed to load the right implementation. Unfortunately, this is a problem for create-react-apps. They look at end env variable process.env.NODE_BACKEND, which cannot be set in CRA (the REACT_APP prefix is required). In addition, it seems that even if this env variable is set, webpack will still try to bundle allrequire() calls, causing the SyntaxError to be triggered in Safari and aborting the load.
The solution that worked for me was to use the IgnorePlugin on the native/bn.js file, which will cause webpack to use the version intended for browsers:
new webpack.IgnorePlugin({
resourceRegExp: /native\/bn/,
contextRegExp: /bcrypto/
})
However, to use this, we will need to eject, or, use a wrapper like craco which allows the CRA config to be customized. The latter might look like this.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
As discussed on Discord:
bcoin/lib/protocol/networks.js
and possibly others.bcrypto
usesBigInt
, which some browsers do not support. The library provides an alternative implementation of its big number backend intended for browsers. Apparently, their first approach is to mapping each file to its browser-version inpackage.json
. webpack/cra seems not to respect this.Secondly, the file
bcrypto/lib/bn.js
is supposed to load the right implementation. Unfortunately, this is a problem for create-react-apps. They look at end env variableprocess.env.NODE_BACKEND
, which cannot be set in CRA (theREACT_APP
prefix is required). In addition, it seems that even if this env variable is set, webpack will still try to bundle allrequire()
calls, causing the SyntaxError to be triggered in Safari and aborting the load.The solution that worked for me was to use the IgnorePlugin on the
native/bn.js
file, which will cause webpack to use the version intended for browsers:However, to use this, we will need to eject, or, use a wrapper like
craco
which allows the CRA config to be customized. The latter might look like this.The text was updated successfully, but these errors were encountered: