Get rid of the DEPTH_ZERO_SELF_SIGNED_CERT error in NextJS when using a self signed SSL certificate.

Problem Statement

Recently, I encountered the Error DEPTH_ZERO_SELF_SIGNED_CERT with a NextJS app. After millenias of debugging, of course, since no meaningful error message arose. My app simply refused to process requests to the /api/* routes of the app.

Reading multiple GitHub Discussion, GitHub Issues and StackOverflow answers like:

brought me nowhere.

There are several development scenarios in which self signing a certificate is useful and common practice so I was a bit salty about the lacking support.

Solution

I found the solution to this problem buried somewhere deep in the Node documentation. There is an option to disable the rejection of unauthorized TLS certiticates NODE_TLS_REJECT_UNAUTHORIZED. So, adding this to NextJS dev script did the trick for me:

...
"scripts": {
"dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 next dev",
...
},
...