[Solved] How fix "BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default" error?

Article Ab Siddik

Problem

Webpack 5 no longer do auto-polyfilling for node core modules.



Solution 1:

You can add support for Node.js core modules with node-polyfill-webpack-plugin. Run - 

npm install node-polyfill-webpack-plugin

Add this code on webpack.config.js:

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

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


Solution 2:

If you don’t need Polyfills for the node development, you can update your webpack.config.js like this -

module.exports = {
 target: 'node',
};


Solution 3:

First install path browserify - 

npm install path-browserify 

Then change webpack configuration -

module.exports = {
    ...
    resolve: {
        alias: {
            path: require.resolve("path-browserify")
        }
    }
};

Thank you for reading the article. If you face any problem, please comment below.