Resolving the Webpack Polyfills Breaking Change When Upgrading an Angular App

While working on upgrading an Angular application, which is several versions behind, to the latest version, I encountered the following error during build:

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.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }

This was happening because one of the developers imported isNullOrUndefined from util in two components. I did some Googling, and found a few issues on GitHub, which included some various workarounds, and strangely enough, became heated -- people were expressing hostility over this issue, and the factors around it.

But amidst all the chaos, one poster stated the following:

I solved this issue by installing util

npm i util

Could it be that simple?

Sure enough, it was.

So, if you're running into this issue, and wading through a stream of workarounds, in this case, the simple approach worked. I'm not sure if it will work in every case, but when it came to this one, with util, it did the trick.

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

How to Determine if a Column Exists in a DataReader

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

Silent Renew and the "login_required" Error When Using oidc-client