Module not found: Error: Can't resolve 'crypto' React

Viewed 10033

I installed the jsonwebtoken package and ever since I'm getting the following error on running the React app : enter image description here

I tried installing the crypto-browserify package but that too didn't resolve the issue.

4 Answers

Try adding the following just after the devDependencies in your package.json

"devDependencies": {
    ...
},
"browser": {
    "crypto": false
}

For me installing crypto-browserify worked flawlessly. You can do this by running the command

yarn add crypto-browserify 

or if you prefer you can install it by doing

npm i crypto-browserify

This npm will install almost all dependencies of node.js crypto module, check what are available and what are not in case you need more information.

I was facing the same issue. I was trying to generate the keys on in React and was getting the same issue. Now the issue is resolved. Just follow the steps given in link https://github.com/ChainSafe/web3.js#troubleshooting-and-known-issues Also add these two in package.json

"dependencies": {
   "crypto": "npm:crypto-browserify",
   "stream": "npm:stream-browserify",
}

Try installing crypto-browserify package and see if that works. If you still see that error try deleting your node_modules folder and install all packages again.

Related