'How to stop nextJS build if error is thrown?

I have like a 100 static pages generated every time the website is built. But the problem that I am facing is the build tries to create all 100 pages, even if one of the 100 pages suppose 20th page has had an error thrown for whatever reason.

I am looking for a way to stop the build as soon as there is a single instance of webpage not building successfully.

I am using nextJS and been using 'next build' to create a build.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source