'Node.js webpack5 error, Module not found; BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core

I'm constantly getting this error message and don't have a clue how to solve it:

Error screenshot



Solution 1:[1]

The thing is Webpack v5 no longer adds polyfills for Node.js built-ins and you should choose between:

  • install polyfills and resolve them; or
  • turn them off using new Webpack API.

If you choose the second option, use the Putout code transformer I’m working on, it will fix all the things for you with help of @putout/plugin-webpack. Here is what it looks like:

convert-node-to-resolve-fallback fixes webpack compilation error:

Module not found: Error: Can't resolve 'path'`

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.

Incorrect code:

module.exports = {
    node: {
        path: 'empty',
        buffer: 'empty',
        crypto: 'empty'
    },
};

Correct code:

module.exports = {
    resolve: {
        fallback: {
            path: false,
            buffer: false,
            crypto: false
        },
    },
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1