đ§Webpack 5 Polyfill Issue
While setting up a new web3 project from scratch, you might face multiple issues with webpack 5. This issue is caused due to the fact that the web3.js
and ethers.js
packages have certain dependencies, which are not present within the browser environment by webpack 5. Hence, you require certain node polyfills to be added to your project, while overriding the configurations to enable their usage. When that is done, your project should be able to utilise the web3.js
and ethers.js
packages easily without any issues.
In this guide, we have added instructions of adding the polyfills of some of the commonly used web frameworks:
For React
If you are using create-react-app
version >= 5 you may run into these issues. The issue can be resolved following the instructions below:
Solution
Install
react-app-rewired
and the missing modules into your applicationUsing
Create
config-overrides.js
in the root of your project folder with the content
Within
package.json
change the scripts field for start, build and test. Instead ofreact-scripts
replace it withreact-app-rewired
The missing Nodejs polyfills should be included now and your app should be functional with web3.
If you want to hide the warnings created by the console:
In config-overrides.js
within the function, add:
If you're using craco
, similar changes need to be made to craco.config.js
If you have any questions, please feel free to ask on the Banana SDK Discord forum.
Last updated