javascriptreactjswebpackreact-scripts

Upgrade the react-script from 4 to 5 cause errors on polyfills


I upgraded my React from 17 to 18 and upgrade the react-script from 4 to 5, when I want to run the app below errors occur:

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.

Solution

  • the error saying that webpack < 5 used to include polyfills for node.js . it seems you are using webpack 5 so is no longer the case . to solve this error :

    1- install node-polyfill-webpack-plugin : npm install node-polyfill-webpack-plugin

    2- go to webpack.config.js and add this : const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

    module.exports = {
        // Other rules...
        plugins: [
            new NodePolyfillPlugin()
        ]
    }