Module not found errors
Closed this issue · 5 comments
Hi, I have several errors of the same type when I try to use require("@alch/alchemy-web3")
. I'm following this guide
Errors look like:
Compiled with problems:
ERROR in ./node_modules/cipher-base/index.js 3:16-43
Module not found: Error: Can't resolve 'stream' in '/home/.../node_modules/cipher-base'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/eth-lib/lib/bytes.js 9:193-227
Module not found: Error: Can't resolve 'crypto' in '/home/.../node_modules/eth-lib/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
ERROR in ./node_modules/ethereumjs-util/dist.browser/account.js 39:31-48
Module not found: Error: Can't resolve 'assert' in '/home/.../node_modules/ethereumjs-util/dist.browser'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
- install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "assert": false }
I tried to run the compiled tutorial but got the same errors.
I'm running into this issue too. @gpalshin were you able to resolve it by chance?
@joshslee In my case, the error occurs when using @alch/alchemy-web3 or web3 with the latest version of React. I managed to run the compiled tutorial, but with a big number of hard and critical vulnerabilities.
You can try to use ethers instead of alchemy-web3:
npm install ethers
Note, that you can also use alchemy API with ethers
by calling new ethers.providers.AlchemyProvider()
, see docs.
@gpalshin thanks for sharing! good news is that it looks like it's known issue for webpack 5 that's being resolved. I managed to do a hacky work-around it, credit: facebook/create-react-app#11756
@gpalshin thanks for sharing! good news is that it looks like it's known issue for webpack 5 that's being resolved. I managed to do a hacky work-around it, credit: facebook/create-react-app#11756
I am having a similar issue, I have added the three dependencies above to my package.json file however, I am still getting the same error. Can you please explain/show how you got the error messages to go off?
This is a documented issue with webpack 5. You can read more about how to add the missing polyfills manually in the web3 documentation.
I'm going to mark this issue as closed but feel free to ask any other questions you may have!