'CryptoJS.AES is Undefined but only when passing a WordArray

I've used CryptoJS.AES.encrypt(stringMessage, stringKey) without any issues for a while. Now I am trying to pass a WordArray instead of a string and suddenly CryptoJS.AES is not recognized and I get TypeError: Cannot read properties of undefined. I tried passing two WordArray parameters, or one string and one WordArray and none work. Here is a simple example:

  let arr: CryptoJS.lib.WordArray = CryptoJS.enc.Utf8.parse("hello");
  let key: CryptoJS.lib.WordArray = CryptoJS.PBKDF2("pass", "salt");
  
  // This works
  let encrypted1 = CryptoJS.AES.encrypt("hello", "pass"); 

  // This doesn't
  let encrypted2 = CryptoJS.AES.encrypt(arr, key);

I tried the suggestion here but it didn't work. Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source