cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to access CryptoJs in magento 2.4.4

Unable to access CryptoJs in magento 2.4.4

<script>
     require([
    "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js",
    ], function() { 
        console.log(CryptoJS);
    });
</script>

unable to access "CryptoJs" variable which is return by the library.but the same variable accessible outside magento directories .

 

Error - 

(index):504 Uncaught ReferenceError: CryptoJS is not defined
    at (index):504:21
    at Object.execCb (require.js:1696:33)
    at Module.check (require.js:883:51)
    at Module.<anonymous> (require.js:1139:34)
    at require.js:134:23
    at require.js:1189:21
    at each (require.js:59:31)
    at Module.emit (require.js:1188:17)
    at Module.check (require.js:938:30)
    at Module.enable (require.js:1176:22)
2 REPLIES 2

Re: Unable to access CryptoJs in magento 2.4.4

Hi @santosh_patel ,

 

In your requirejs-config.js file add below code

 

var config = {
    paths: {
        crypto: 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js' 
},
};

 

After that you can use it like below

require(['jquery', 'crypto'], function ($, crypto) { 
});

 

Problem Solved? Accept as Solution!

Hope it helps!
Thanks

Ankit Jasani

Re: Unable to access CryptoJs in magento 2.4.4

Can I participate in your discussion? You know, the question about this has always been important to me because this way of making money is worth it. Many people are afraid of trading, but I think that after reading the reviews of stock broker, it will be easier to understand that with the right applications. I still do it, even though I have already invested a lot of money in trading.