Nuxt
Learn how to set up and configure Sentry in your Nuxt application using the installation wizard, capture your first errors, and view them in Sentry.
You need:
- A Sentry account and project
- Your application up and running
- Nuxt version
3.7.0or above (3.14.0+ recommended)
The AI-powered sentry init flow is currently experimental. To use the existing framework-specific setup instead, see the option below, or check out the Manual Setup guide.
Run the Sentry init command in your project directory to automatically configure Sentry in your Nuxt application.
The command guides you through setup and asks which optional Sentry features you want to enable beyond error monitoring.
npx sentry@latest init
npx sentry@latest init
You can prevent ad blockers from blocking Sentry events using tunneling. Use the tunnel option in Sentry.init to add an API endpoint in your application that forwards Sentry events to Sentry servers.
This will send all events to the tunnel endpoint. However, the events need to be parsed and redirected to Sentry, so you'll need to do additional configuration on the server. You can find a detailed explanation on how to do this on our Troubleshooting page.
Sentry.init({
dsn: "___PUBLIC_DSN___",
tunnel: "/tunnel",
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
tunnel: "/tunnel",
});
The sentry init command checks the integration files it creates or modifies before it finishes. To confirm runtime events are reaching Sentry, start your Nuxt app, exercise the parts of your app that should send events, and then check your Sentry project.
If you used the Nuxt installation wizard instead, you can also verify your setup with the example page or component it creates.
To test Sentry, you can run your Nuxt application in either production or development mode. We recommend testing in production mode as it most closely resembles your deployed application's environment.
By default, the SDK will add the server config as sentry.server.config.mjs to the build. To find the exact path to this file, enable debug mode in your Sentry configuration within nuxt.config.ts. Sentry will then print the exact path during the build process.
After building with nuxi build, run your project and make sure to load Sentry on the server side by explicitly adding it via --import (read more about this flag in Installation Methods).
# Start your app after building your project with `nuxi build`
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
# Start your app after building your project with `nuxi build`
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
The server config file is generated in the .nuxt directory the first time you run nuxt dev. If you delete your .nuxt directory, you'll need to run nuxt dev once without the NODE_OPTIONS variable to regenerate it.
If you only want to use Sentry on the client-side or only need basic error monitoring on the server side, you can omit the --import flag when running your application.
# Run the dev server with the --import flag after running `nuxt dev` once (without the flag)
NODE_OPTIONS='--import ./.nuxt/dev/sentry.server.config.mjs' nuxt dev
# Run the dev server with the --import flag after running `nuxt dev` once (without the flag)
NODE_OPTIONS='--import ./.nuxt/dev/sentry.server.config.mjs' nuxt dev
If you used the Nuxt installation wizard, after building and running your project:
- Open the example page
/sentry-example-pagein your browser. For most Nuxt applications, this will be at localhost. - Click the "Throw sample error" button. This triggers two errors:
- a frontend error
- an error within the API route
Sentry captures both of these errors for you. Additionally, the button click starts a performance trace to measure the time it takes for the API request to complete.
Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).
Important
Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.
At this point, you should have integrated Sentry into your Nuxt application and should already be sending error and performance data to your Sentry project.
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Learn how to manually capture errors
- Continue to customize your configuration
- Get familiar with Sentry's product features like tracing, insights, and alerts
- Learn how to track your Vue components or your Pinia store
- Learn how to add support for different Nitro deployment presets (like Cloudflare)
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").