Insights

When 'Next Build' In Sitecore JSS Site Fails

With 'Unable To Verify The First Certificate'

Running 'Next Build' Fails With A Certificate Error

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.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet David Austin

Development Team Lead | Sitecore Technology MVP x 3

📷🕹️👪

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David