Angular Error: Module not found: Error: Can’t resolve ‘zlib’ in

If you are getting these weird compilation errors in your Angular project suddenly while working in your Angular project:

Error: Module not found: Error: Can't resolve 'zlib' in /node_modules/body-parser/lib
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
Module not found: Error: Can't resolve 'fs'
Module not found: Error: Can't resolve 'stream'
Module not found: Error: Can't resolve 'path'
Module not found: Error: Can't resolve 'crypto'

The reason for that issue could be that you have accidentally imported an incorrect import in your component. It could be because of an import imported from express, example:

import { Router } from 'express';

The solution for the above issue will be to replace the above line with the following:

import { Router } from '@angular/router';

Run the ng serve again and the compilation issue should be fixed.