How to avoid «Your connection is not private» / `NET::ERR_CERT_AUTHORITY_INVALID` for localhost in Windows 10?

NET::ERR_CERT_AUTHORITY_INVALID means that the root certificate is invalid or absent.
In my case, the root certificate was absent because I reinstalled Windows.