How to install Polyfills with Webpack 5
Last updated
Last updated
For Webpack 5 users, who have not installed polyfills in their projects there's an additional step that needs to be done in order to use social authentication. This step is required by the web3auth
library, AsteroidKit uses that. The following guide describes how to install the necessary packages.
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 utilize the web3.js
and ethers.js
packages easily without any issues.
If you are using create-react-app
version >= 5 you may run into issues building. The issue can be resolved following the instructions below:
Solution
Install react-app-rewired
and the missing modules in your application
npm
Yarn
Create config-overrides.js
in the root of your project folder with the content:
Within package.json
change the scripts field for a start, build and test. Instead of react-scripts
replace it with react-app-rewired
Before the change:
After the change:
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 override
function, add:
If you're using craco
, similar changes need to be made to craco.config.js
The original article can be found here: