many components having issues and cant be installed from online package manager on the above mentioned version of Lazarus & fpc , one of them is htmlviwer
There are exceptions, but packages inside OPM usually works with stable version of FPC/Lazarus(currently FPC 3.2.2 and Lazarus 2.2.4). If you wish to use developer versions you are on your own.
HtmlViewer: I checked the author's github page, it was modified more then 3 years ago. No wonder it does not work with trunk/main.
how to overcome these compilation errors on this or on any other components
By fixing the issues and creating pull requests, but don't expect OPM to support every available FPC, Lazarus version. I will quote forum user @avra, he explained the issue in one of his earlier post:
OPM is distributed with so many LAZ/FPC combos, that authors even in their craziest effort would not be able to test them all. For example, some users will try to install package on some old LAZ 1.6 with FPC 3.04 on x86 Debian, someone else will try the same package on LAZ 2.0 with FPC 3.2 on x64 Windows, another one will try with LAZ trunk and FPC trunk on Pi (32 or 64) or even some old ARMv5 or ARMv6 board, and another while chasing a bug that shows just on Apple M1. Do you really expect that everything compiles everywhere in all possible combos? That is not a realistic expectation. A package can be made for latest FPC, while you might have old 3.0.4, or FPC and LAZ move on but author did not upgrade his package (or OPM version was not yet updated). To ease things a little, some packages provide info on what platform and FPC/LAZ combos they have been tested. As an example, most of CodeTyphon packages in OPM (they all have pl_ prefix) are tested with stable FPC/LAZ combo on Windows x32 and Linux x64. But even in such a case, you can not expect a Windows specific package to magically work on Linux just because it is available in OPM.