4

I've been running ng serve --ssl on my current project for some time with no issue. The first time I ran it, angular automatically created a self-signed cert. My browser rejected it which is expected, so I exported it and imported it into my local trusted root certificates and turned on the Chrome flag chrome://flags/#allow-insecure-localhost to allow me to use untrusted certs from localhost. So all was well for a while.

Today I'm running ng serve --ssl and I'm getting the following error:

"Your connection is not private"

"NET::ERR_CERT_DATE_INVALID"

After inspecting the cert, sure enough, the cert has expired.

How do I get ng serve --ssl to create a new cert and stop using the old expired one? I've already tried deleting the old expired one in my local cert management console but the same old expired cert is re-used whenever I run ng serve --ssl

Post Impatica
  • 14,999
  • 9
  • 67
  • 78

1 Answers1

18

Apparently the Angular CLI only creates a 1 month certificate when it autogenerates a cert. I downloaded and used Micrsoft's SysInternals ProcessMonitor to find the fix.

  1. Stop ng serve --ssl if it's still running
  2. Delete node_modules\webpack-dev-server\ssl\server.pem
  3. Restart ng serve --ssl and you should have a new 30 day cert.
Post Impatica
  • 14,999
  • 9
  • 67
  • 78
  • 2
    With the latest version of Angular, the server.pem can now be found under node_modules/.cache/webpack-dev-server – Ryan Durkin Dec 05 '22 at 12:38
  • 1
    If you're building an ASP.Net Core with Angular App through Visual Studio, the pem file can be found in %APPDATA%\ASP.NET\https\ Deleting this file and then restarting the app caused the angular cli to regenerate a new certificate – Ryan Durkin Dec 05 '22 at 12:42