Search code examples
javascriptnode.jsencryptionmethodscryptojs

how crypto-js hide the class method?


Start With This

import crypto from 'crypto-js'
global.crypto = crypto

When I Access crypto from the browser Console I got the following error

crypto['AES'].encrypt('MyString', 'pass').toString() // Uncaught TypeError: Cannot read property 'encrypt' of undefined(…)

but when I access it from Node it works -_-

crypto['AES'].encrypt('MyString','pass').toString() // Encrypted String

How Crypto JS do this? can't directly access from the browser, but accessible in node?


Solution

  • I believe your issue is that 'crypto' is reserved internally by the window object. Try importing under another name.