I have (succesfully) done an
npm install --save crypto-js
in the current project. It shows up in package.json:
$grep crypto package.json
"crypto-js": "^4.0.0",
Then in a local project javascript file I am trying to use it and have not figured it out. The following has been attempted:
var CryptoJS = require("crypto-js");
I have also tried to use the import approach after downloading the aes.js to the same local directory:
<script type="text/javascript" src="aes.js"></script>
This results in:
Uncaught ReferenceError: require is not defined at my-project-worker.js:1
Uncaught ReferenceError: CryptoJS is not defined
at encrypt (audio-clips-worker.js:168)
at audio-clips-worker.js:235
at Set.forEach (<anonymous>)
at onmessage (audio-clips-worker.js:229)
Finally I tried leaving an absolute url:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
That gave the same "CryptoJS is not defined" error. What are working options here - and what steps are missing or need to be done differently?
const CryptoJS = require('crypto-js'); console.log(CryptoJS.HmacSHA1('Message', 'Key'));.