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

A quick solution to resolve the 'could not find file for module' error message for 'crypto-js'.

Last updated on 11/21/2021


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.