Is there a way to stop npm run build programatically in Next.js as soon as a certain Error occurs in getStaticProps?
Just throwing an Error does not stop the build process.
I've been trying to achieve the same thing but apparently there is no official way. What I've tried is the following code inside next.config.js:
module.exports = async (phase, { defaultConfig }) => {
try {
console.log("fetching app info", phase)
const appInfo = await fetchAppInfo()
fs.writeJson("./src/appInfo.json", appInfo)
} catch (e) {
console.log(e)
throw e
}
return yourConfig
}
If you don't return the expected config for next js, the build procedure will be cancled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With