. Advertisement .
..3..
. Advertisement .
..4..
The error: “Module not found: Error: Can’t resolve ‘crypto’” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
When Does The Error: “Module not found: Error: Can’t resolve ‘crypto’” Happen?
When running ng serve, you might get the below list of problems. This can be the one you encounter:
ERROR in ./node_modules/aws-sign2/index.js Module not found: Error: Can't resolve 'crypto' in '/Users/MYPC/Documents/Myproj/ProName/node_modules/aws-sign2'
ERROR in ./node_modules/aws4/aws4.js Module not found: Error: Can't resolve 'crypto' in '/Users/MYPC/Documents/Myproj/ProName/node_modules/aws4' ERROR in ./node_modules/ecc-jsbn/index.js
How To Solve The Error: “Module not found: Error: Can’t resolve ‘crypto’”
Approach 1: Include the below line in the package.json
Simply include “crypto“: false in the package.json file, immediately after the devDependencies section, to fix this issue.
"devDependencies": {
...
},
"browser": {
"crypto": false
}
Approach 2: Include the following setting in tsconfig.ts
To remove this warning, simply add the following value to the tsconfig.ts file within that project.
"compilerOptions": {
"baseUrl": "./",
"paths": {
"crypto": [
"../../node_modules/crypto-js"
]
}
Approach 3: Set “crypto”: false
If you don’t like utilizing crypto, you’ll need to adjust any dependencies that cause “can’t resolve x” problems. The key section of your package.json, for instance, can be:
"browser": {
"crypto": false,
"
Approach 4: Use this version of crypto-js
Besides the mentioned solutions above, you can resolve “Module not found: Error: Can’t resolve ‘crypto’” error by trying to use this version of crypto-js.
npm install [email protected]
Using best practices and design patterns, CryptoJS is a growing library of secure and common cryptographic methods implemented in JavaScript. They are quick and provide a dependable, uncomplicated user interface. CDN links for Crypto Js 3.1.9-1 also contain JS files in their minified forms. Download the source packages for NPM, Yarn, and Github for Crypto Js 3.1.9-1, or follow the installation instructions there.
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “Module not found: Error: Can’t resolve ‘crypto’” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Read more
→ Tips On Solving The Error: “ModuleNotFoundError: No module named ‘wtforms.compat’”
Leave a comment