Home > Software design >  Node.js webpack5 error, Module not found; BREAKING CHANGE: webpack < 5 used to include polyfills
Node.js webpack5 error, Module not found; BREAKING CHANGE: webpack < 5 used to include polyfills

Time:03-22

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

Error screenshot

Can anyone please help me?

CodePudding user response:

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',
    },
};

Correct code:

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

CodePudding user response:

This is my whole error:

Error message

  • Related