Closed dominic-p closed 6 years ago
I've just ran into this myself and had to work around it by setting externals: { crypto: 'null'}
in my webpack config. That drops it into the right condition for the browser. IgnorePlugin would probably be better but i couldn't get it to match.
As for why this is happening my best guess is that because this code is contained in an immediately executed function it's getting picked up by webpack?
I fixed this in one of my projects by telling webpack to not parse sjcl.js at all:
noParse: [
/sjcl\.js$/,
]
@ryanand26's solution works perfectly for me. Should I close this?
Please consider to reopen this one. It's annoying to fix that issue in all applications that uses sjcl together with webpack. In a related issue @ef4 suggested this fix:
The right place to fix this is still upstream in sjcl, probably by having separate entrypoint for browesr vs node, and using the main and browser fields in package.json to distinguish them.
When I import sjcl I notice that webpack adds a browser compatible version of the node crypto module to my bundle (significantly increasing the size).
From what I've read, this should be avoidable, but the code where the require is made already seems to be doing everything right to avoid this.
I'm not sure if this is a bug with the way the crypto module is required (maybe the conditional just needs to be switched so the check for
window
comes before the check formodule
?), or a bug with webpack, or a problem with my webpack configuration. But, I wanted bring it up here to see what the devs think.Thanks, btw, for the fantastic library.