Crypto JS Module Error

I was attempting to add a the crypto-js npm package to my tools Angular app.

I ran this command to install the package:

npm install crypto-js

Everything installed properly, next I tried to add the import package to one of my Angular services using this code:

import CryptoJs from 'crypto-js';

I was met with the following error:

could not find a declaration file for module 'crypto-js'

Solution

Change your import statement from this:

import CryptoJs from 'crypto-js';

to this:

import * as CryptoJS from 'crypto-js';

Additional Troubleshooting

If you need type support, install the types for CryptoJs:

npm install @types/crypto-js

Conclusion

I hope this helped you add the crypto-js npm package to your Typescript application.

For further troubleshooting check out this Stack Overflow answer.

FeedbackI'd love to hear your feedback!
Did this blog post help fix your issue? Still having trouble?
Tweet At Me
Brendan SlukeSoftware Engineer

Hi, I'm Brendan Sluke and I love writing code and blogging about software engineering.

Follow Me On Twitter Read My Blog
Recommended Blog PostsBlog Posts I Think You Will Find Interesting
Go Back To Top of Page