If you've built your Sitecore JSS NextJs setup via Docker, then you may run into a scenario, depending on your configuration, where when you run a next build
command you get an error back that resembles the following:
> Build error occurred
FetchError: request to https://cm.abccompany.localhost/sitecore/api/graph/edge failed, reason: unable to verify the first certificate
at ClientRequest. (C:\abccompany\src\rendering\abccompany\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
Now, you may be asking yourself, why run next build
in the first place, when I save it updates my application? Well, for one, if you're deploying to services such as Vercel, out-of-the-box they run a next build
command upon deployment. So running it locally is just good programming and will likely save you a bad deployment in the future.
The Quick Fix
This is not a fix you should do in your production environment. This is the only one I would recommend performing in a local or dev environment.
Open up your .env
file in the root of the project folder. You will want to add the following line:
NODE_TLS_REJECT_UNAUTHORIZED=0
All this does is ignore the error and let the build continue, but it will get you past it to resolve any other errors you may be experiencing or find surprising.