How to prevent broken Nuxt builds from deploying your site on Netlify?

We love fast Nuxt builds on Netlify. But some builds ended up being impossibly fast. Turns out when a Nuxt build produces errors, the Netlify deploy still succeeds. In other words, broken Nuxt sites end up live in production. So how can we avoid this?

Help failing

Nuxt has no documentation online on how to abort builds with errors. Luckily there is something in the output of "nuxt generate --help command":

Turns out, all we need to do is add a "--fail-on-error" flag to our build command:

nuxt generate --fail-on-error

That’s it!