How to create React App including Web3 using create-react-app? I am getting Module not found Error. BREAKING CHANGE: webpack < 5 used

Solution 1:

Run npm install @web3-react/core web3 @web3-react/injected-connector after running npm uninstall web3 and deleting package-lock.json and node_modules

You DO NOT need to downgrade react or install any polyfill plugins for this

Solution 2:

That is because Webpack 5 no longer does auto-polyfilling for node core modules.

Simply in order to modify the webpack.config.js in Create React App, you have to run

npm run eject

this will create a config directory and inside you will have webpack.config.js.

 npm i node-polyfill-webpack-plugin

then inside webpack.config.js:

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

add this to plugins array

plugins: [
    new NodePolyfillPlugin()
  ],

I explained how to set up with create-react-app here :

Web3 Issue : React Application not compiling

I also explained to solve with webpack:

Webpack breaking change