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:
- https://github.com/vercel/next.js/discussions/10935
- https://stackoverflow.com/questions/70440486/locally-developing-nextjs-and-fetch-getting-self-signed-cert-error/71558621
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",...},...