Bovenkant pagina

Blog

Abort failing Nuxt builds on Netlify

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?

Site is live even though errors occur during Nuxt build

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:

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!

Failing successfully

if (cmd.argv['fail-on-error'] && errors.length > 0) {
  throw new Error('Error generating pages, exiting with non-zero code')
}

When Netlify receives a "non-zero code" it will fail the deploy:

Build throws errors and this prevents broken site going live

This is exactly what we want. Because we only want to put our site live when a build is successful.

And naturally this feeds back nicely into our development workflow on GitHub with ❌ and ✅ for failing and succeeding deploys:

Failing by default?

There may be scenarios where you want builds with errors to still deploy your site. However we think builds would be more predictable if they would fail on error by default. Maybe Nuxt will solve this in the future. For now, appending nuxt generate with --fail-on-error will fix our Nuxt builds on Netlify.

← Alle blogposts

Ook verliefd op het web?

Technologie en gebruikservaring. Snel, toegankelijk en een plezier om te gebruiken. Maar ook een plezier om te ontwikkelen. Geldt dit ook voor jou?
Kom ons versterken