- Errors during the Vue rendering lifecycle (SSR & CSR)
- Server and client startup errors (SSR + CSR)
- Errors during Nitro server lifecycle (
server/directory) - Errors downloading JS chunks
Vue Errors
Hook into Vue errors usingonErrorCaptured from Vue’s composition API:
vue:error hook that will be called if errors propagate to the top level. If you’re using an error reporting framework, you can provide a global handler through vueApp.config.errorHandler to receive all Vue errors.
The
vue:error hook is based on the onErrorCaptured lifecycle hook.Startup Errors
Nuxt calls theapp:error hook if there are errors starting your Nuxt application.
This includes:
- Running Nuxt plugins
- Processing
app:createdandapp:beforeMounthooks - Rendering your Vue app to HTML (during SSR)
- Mounting the app (on client-side) - handle this with
onErrorCapturedorvue:error - Processing the
app:mountedhook
Nitro Server Errors
You cannot currently define a server-side handler for these errors, but you can render an error page (see the Error Page section below).JS Chunk Loading Errors
You might encounter chunk loading errors due to network connectivity failures or new deployments that invalidate old hashed JS chunk URLs. Nuxt provides built-in support by performing a hard reload when a chunk fails to load during route navigation. Change this behavior usingexperimental.emitRouteChunkError:
false: Disable error handling'manual': Handle errors yourself- Default: Automatic hard reload
Error Page
When Nuxt encounters a fatal error, it will either render a JSON response (if requested with
Accept: application/json header) or trigger a full-screen error page.- Processing your Nuxt plugins
- Rendering your Vue app into HTML
- A server API route throws an error
- Processing your Nuxt plugins
- Before mounting the application (
app:beforeMounthook) - Mounting your app if the error wasn’t handled with
onErrorCapturedorvue:error - The Vue app is initialized and mounted in browser (
app:mounted)
Customize the Error Page
Customize the default error page by adding~/error.vue in your application’s source directory:
Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use
useError in middleware to check if an error is being handled.For custom errors, use
onErrorCaptured composable in a page/component setup function or vue:error runtime hook in a Nuxt plugin.Clear Errors
Call theclearError helper function to remove the error page and optionally redirect:
Error Utils
useError
Returns the global Nuxt error being handled:createError
Create an error object with additional metadata:message or an object containing error properties.
If you throw an error created with createError:
- Server-side: It triggers a full-screen error page that you can clear with
clearError - Client-side: It throws a non-fatal error for you to handle. Set
fatal: trueto trigger a full-screen error page
showError
Trigger a full-screen error page:setup() functions. It triggers a full-screen error page that you can clear with clearError.
We recommend using
throw createError() instead.clearError
Clear the currently handled Nuxt error:Render Error in Component
Use the<NuxtErrorBoundary> component to handle client-side errors within your app without replacing your entire site with an error page:
- Prevents errors from bubbling to the top level
- Renders the
#errorslot instead of the default slot - Receives
erroras a prop in the error slot - Automatically clears errors when navigating to another route
Best Practices
- Use error boundaries: Wrap potentially error-prone components with
<NuxtErrorBoundary> - Report errors: Integrate error tracking services via
vue:errorhook - Provide fallbacks: Always show users a way to recover from errors
- Test error states: Ensure your error pages and boundaries work correctly
- Clear errors properly: Always check plugin state before clearing errors