I have an Angular-CLI project which makes use of the object-hash library for creating hashes from objects. Normally I would just put
import * as objectHash from 'object-hash'
at the top of one of my component files and then do const hash = objectHash(obj)
anywhere I needed a hash.
I just upgraded my project to Angular 8 and suddenly, the Angular project serves great, but when I run a production build, I get an error: Cannot read property 'crypto' of undefined
.
This is because Angular 8 generates differential JavaScript, generating some bundles for newer browsers as <script type="module">
and older browsers as <script nomodule>
. When a script has type="module"
, apparently this
is treated differently- so the object-hash library's reference to this
is broken: https://github.com/puleos/object-hash/issues/71
Does anyone have any insight into how I might resolve this?
Potential solutions I'm seeing are:
Importing the object-hash library differently somehow
Using a completely different browser-compatible object-hashing library (I haven't found one yet)
After the commit 1e0835c, upgrading object-hash to v2.0.1
should solve the problem (see the author's comment in the reported issue)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With