Skip to content

Commit c20b570

Browse files
authored
docs(nuxt): Add Nuxt wizard instructions (#11984)
* docs(nuxt): Add Nuxt wizard instructions * update wizard instructions and add troubleshooting item * review suggestions * add link to installation methods
1 parent 3d4430c commit c20b570

File tree

8 files changed

+149
-175
lines changed

8 files changed

+149
-175
lines changed

docs/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,21 +470,21 @@ Learn more about fixing these caching issues in the <PlatformLink to="/sourcemap
470470
471471
```json {tabTitle:npm} {filename:package.json}
472472
"overrides": {
473-
"@vercel/nft": "^0.27.4"
474-
}
473+
"@vercel/nft": "^0.27.4"
474+
}
475475
```
476476
477477
```json {tabTitle:yarn} {filename:package.json}
478478
"resolutions": {
479-
"@vercel/nft": "^0.27.4"
480-
}
479+
"@vercel/nft": "^0.27.4"
480+
}
481481
```
482482
483483
```json {tabTitle:pnpm} {filename:package.json}
484484
"pnpm": {
485-
"overrides": {
486-
"@vercel/nft": "^0.27.4"
487-
}
485+
"overrides": {
486+
"@vercel/nft": "^0.27.4"
487+
}
488488
}
489489
```
490490
@@ -501,6 +501,43 @@ Learn more about fixing these caching issues in the <PlatformLink to="/sourcemap
501501
pnpm add import-in-the-middle
502502
```
503503
</Expandable>
504+
505+
<Expandable permalink title="Nuxt: Server-side Nitro is not sending events">
506+
Nuxt builds the server-side Nitro application as ES Modules, which introduces limitations for server-side tracing during development.
507+
Currently, trace collection is only supported when building and running the application. Development mode (`nuxt dev`) is currently not supported.
508+
509+
When running the build output, Sentry needs to be initialized before running the rest of the application. This is done automatically, but might not work for your use case.
510+
Read more about this in <PlatformLink to="/install">installation methods</PlatformLink>.
511+
512+
---
513+
514+
We are currently investigating an issue where the server-side is not correctly initialized with a recent update of Nitro (the server-side toolkit in Nuxt).
515+
516+
We are working on figuring this out ([see issue here](https://github.com/getsentry/sentry-javascript/issues/14514)). For the time being, you can add the following overrides to your application:
517+
518+
```json {tabTitle:npm} {filename:package.json}
519+
"overrides": {
520+
"nitropack": "2.9.7"
521+
"@vercel/nft": "^0.27.4"
522+
}
523+
```
524+
525+
```json {tabTitle:yarn} {filename:package.json}
526+
"resolutions": {
527+
"nitropack": "2.9.7"
528+
"@vercel/nft": "^0.27.4"
529+
}
530+
```
531+
532+
```json {tabTitle:pnpm} {filename:package.json}
533+
"pnpm": {
534+
"overrides": {
535+
"nitropack": "2.9.7"
536+
"@vercel/nft": "^0.27.4"
537+
}
538+
}
539+
```
540+
</Expandable>
504541
</PlatformSection>
505542
506543
If you need additional help, you can [ask on GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose). Customers on a paid plan may also contact support.

docs/platforms/javascript/guides/nuxt/manual-setup.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,33 @@ If you can't (or prefer not to) run the <PlatformLink to="/#install">automatic s
88

99
## Compatibility
1010

11-
The minimum supported Nuxt version is `3.7.0`.
11+
The Sentry Nuxt SDK supports Nuxt version `3.7.0` and above. For best results, we recommend
12+
using Nuxt `3.14.0` or later, which includes updated dependencies critical to the SDK's functionality.
13+
14+
In case you are using Nuxt before version `3.14.0`, add the following overrides:
15+
16+
```json {tabTitle:npm} {filename:package.json}
17+
"overrides": {
18+
"ofetch": "^1.4.0"
19+
"@vercel/nft": "^0.27.4"
20+
}
21+
```
22+
23+
```json {tabTitle:yarn} {filename:package.json}
24+
"resolutions": {
25+
"ofetch": "^1.4.0"
26+
"@vercel/nft": "^0.27.4"
27+
}
28+
```
29+
30+
```json {tabTitle:pnpm} {filename:package.json}
31+
"pnpm": {
32+
"overrides": {
33+
"ofetch": "^1.4.0"
34+
"@vercel/nft": "^0.27.4"
35+
}
36+
}
37+
```
1238

1339
## Install
1440

Lines changed: 2 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,2 @@
1-
To set up the Sentry SDK, register the Sentry Nuxt module and initialize the SDK for client and server. At build time, the Sentry Nuxt Module looks for the following two files:
2-
3-
- Client-Side: `sentry.client.config.ts` in the root containing `Sentry.init`
4-
- Server-Side: `sentry.server.config.ts` in the root containing `Sentry.init`
5-
6-
In these files, you can specify the full range of <PlatformLink to="/configuration/options">Sentry SDK options</PlatformLink>.
7-
8-
9-
### Nuxt Module Setup
10-
11-
Add the Sentry Nuxt Module to your `nuxt.config.ts` file:
12-
13-
```javascript {filename:nuxt.config.ts}
14-
export default defineNuxtConfig({
15-
modules: ["@sentry/nuxt/module"]
16-
});
17-
```
18-
19-
Adding this module enables the Sentry SDK in your Nuxt application. The Sentry Nuxt Module will then automatically look for the Sentry configuration files and initialize the SDK accordingly.
20-
21-
### Client-side Setup
22-
23-
Add a `sentry.client.config.ts` file to the root of your project (this is probably the same level as the `package.json`). In this file, import and initialize Sentry, specifying any SDK options for the client:
24-
25-
```javascript {filename:sentry.client.config.ts}
26-
import * as Sentry from '@sentry/nuxt';
27-
28-
Sentry.init({
29-
// If set up, you can use your runtime config here
30-
// dsn: useRuntimeConfig().public.sentry.dsn,
31-
dsn: "___PUBLIC_DSN___",
32-
33-
// We recommend adjusting this value in production, or using tracesSampler
34-
// for finer control
35-
tracesSampleRate: 1.0
36-
});
37-
```
38-
39-
### Server-side Setup
40-
41-
1. Add a `sentry.server.config.ts` file to the root of your project:
42-
43-
```javascript {filename:sentry.server.config.ts}
44-
import * as Sentry from '@sentry/nuxt';
45-
46-
Sentry.init({
47-
dsn: "___PUBLIC_DSN___",
48-
49-
// We recommend adjusting this value in production, or using tracesSampler
50-
// for finer control
51-
tracesSampleRate: 1.0
52-
});
53-
```
54-
55-
The Nuxt `useRuntimeConfig()` does not work in the Sentry server config due to technical reasons (the config file has to
56-
be loaded before Nuxt is loaded). To be able to use `process.env` you either have to add `--env-file=.env` to your node command
57-
58-
```bash {tabTitle: node}
59-
node --env-file=.env .output/server/index.mjs
60-
```
61-
62-
or use the `dotenv` package:
63-
64-
```javascript {tabTitle: Server Config} {filename:sentry.server.config.ts} {1,3}
65-
import dotenv from 'dotenv';
66-
67-
dotenv.config();
68-
69-
// ... rest of the file
70-
```
71-
72-
<Alert level="warning">
73-
In the beta state of the Nuxt SDK, some features may not work with certain deployment providers. Check the progress on GitHub: [Compatibility with different Deployment Platforms](https://github.com/getsentry/sentry-javascript/issues/14029)
74-
</Alert>
75-
76-
#### Troubleshoot Errors during Server Startup
77-
78-
After adding `sentry.server.config.ts` and building the project, you might get an error like this:
79-
`Failed to register ESM hook import-in-the-middle/hook.mjs`. You can add an override (npm/pnpm) or a resolution (yarn)
80-
for `@vercel/nft` to fix this. This will add the `hook.mjs` file to your build output. See the [underlying issue in the UnJS Nitro project](https://github.com/unjs/nitro/issues/2703).
81-
82-
83-
Nitro updated `@vercel/nft` in Nitro version `2.10.0`, so you might not get this error anymore, and you don't need to
84-
add this override/resolution.
85-
86-
```json {tabTitle:npm} {filename:package.json}
87-
"overrides": {
88-
"@vercel/nft": "^0.27.4"
89-
}
90-
```
91-
92-
```json {tabTitle:yarn} {filename:package.json}
93-
"resolutions": {
94-
"@vercel/nft": "^0.27.4"
95-
}
96-
```
97-
98-
```json {tabTitle:pnpm} {filename:package.json}
99-
"pnpm": {
100-
"overrides": {
101-
"@vercel/nft": "^0.27.4"
102-
}
103-
}
104-
```
105-
106-
**Pnpm and Import-In-The-Middle**
107-
108-
Sentry injects `import "import-in-the-middle/hook.mjs"` in your server entry. This import acts as a hint for node bundlers to really include this file.
109-
As pnpm implements a strict dependency isolation, this import might cause problems.
110-
Per default, `shamefully-hoist` is `false` ([pnpm docs here](https://pnpm.io/next/npmrc#shamefully-hoist)) and this prevents accessing non-declared dependencies.
111-
You probably don't want to change this setting, so you have to explicitly add the dependency `import-in-the-middle`:
112-
113-
```json {tabTitle:pnpm} {filename:package.json}
114-
// only when using pnpm
115-
"dependencies": {
116-
"import-in-the-middle": "^1.11.2"
117-
}
118-
```
1+
To complete your configuration, add <PlatformLink to="/configuration/options/">options</PlatformLink> to your `Sentry.init()` calls.
2+
Here, you'll also be able to set context data, which includes data about the <PlatformLink to="/enriching-events/identify-user/">user</PlatformLink>, <PlatformLink to="/enriching-events/tags/">tags</PlatformLink>, or even <PlatformLink to="/enriching-events/context/">arbitrary data</PlatformLink>, all of which will be added to every event sent to Sentry.
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
```bash {tabTitle:npm}
2-
npm install @sentry/nuxt --save
3-
```
1+
We recommend installing the SDK by running our installation wizard in the root directory of your project:
42

5-
```bash {tabTitle:yarn}
6-
yarn add @sentry/nuxt
3+
```bash
4+
npx @sentry/wizard@latest -i nuxt --org ___ORG_SLUG___ --project ___PROJECT_SLUG___
75
```
86

9-
```bash {tabTitle:pnpm}
10-
pnpm add @sentry/nuxt
11-
```
7+
The wizard will prompt you to log in to Sentry. It will then automatically do the following steps for you:
8+
9+
- create or update Nuxt files with the default Sentry configuration:
10+
- `sentry.(client|server).config.ts` to initialize the SDK
11+
- `nuxt.config.ts` to add build options to add source maps upload and auto-instrumentation via Vite plugins.
12+
- create a `.env.sentry-build-plugin` file with an auth token to upload source maps (this file is automatically added to `.gitignore`)
13+
- add an example page to your frontend app and your server to verify your Sentry setup
14+
15+
After the wizard setup is completed, the SDK will automatically capture unhandled errors, and monitor performance.
16+
17+
You can also <PlatformLink to="/usage/">manually capture errors</PlatformLink>.
18+
19+
<Note>
20+
If the setup through the wizard doesn't work for you, you can also <PlatformLink to="/manual-setup/">set up the SDK manually</PlatformLink>.
21+
</Note>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
## Next Steps
22

33
- Track your Vue Components or your Pinia store by [adding support for client features](/platforms/javascript/guides/nuxt/features/)
4+
- In case you experience any issues during setup or startup, check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
5+
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>.

platform-includes/getting-started-primer/javascript.nuxt.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
This SDK is currently in **beta**. Beta features are still in progress and may have bugs. Please reach out on
33
[GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns.
44
</Alert>
5+
6+
7+
Sentry's Nuxt SDK enables automatic reporting of errors and performance data.
8+
9+
## Compatibility
10+
11+
The Sentry Nuxt SDK supports Nuxt version `3.7.0` and above. For best results, we recommend
12+
using Nuxt `3.14.0` or later, which includes updated dependencies critical to the SDK's functionality.
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1 @@
1-
## Add Readable Stack Traces to Errors
21

3-
The Sentry Nuxt Module uses the [Sentry Vite Plugin](https://www.npmjs.com/package/@sentry/vite-plugin) to upload source maps for both server and client builds.
4-
This means that when you run a production build (`nuxt build`), source maps will be generated and uploaded to Sentry, so that you get readable stack traces in your Sentry issues.
5-
6-
To upload source maps, specify your Sentry auth token as well as your org and project slugs. Set them in the `sourceMapsUploadOptions` option
7-
inside the `sentry` options of your `nuxt.config.ts`.
8-
9-
<Alert level="info">
10-
The module options inside `sentry` are only affecting the **build-time** of the SDK.
11-
</Alert>
12-
13-
<OrgAuthTokenNote />
14-
15-
```javascript {filename:nuxt.config.ts} {3-9}
16-
export default defineNuxtConfig({
17-
modules: ["@sentry/nuxt/module"],
18-
sentry: {
19-
sourceMapsUploadOptions: {
20-
org: "___ORG_SLUG___",
21-
project: "___PROJECT_SLUG___",
22-
authToken: "___ORG_AUTH_TOKEN___"
23-
}
24-
}
25-
});
26-
```
27-
28-
To upload source maps, the Sentry Nuxt Module will automatically enable source map generation in your project if it is not already enabled.
29-
However, you need to explicitly enable source map generation on the client-side. To do this, add the following code to your Nuxt configuration:
30-
31-
```javascript {filename:nuxt.config.ts} {2}
32-
export default defineNuxtConfig({
33-
sourcemap: { client: true }
34-
});
35-
```
36-
37-
This step is necessary because Nuxt sets default values for source maps ([Nuxt docs](https://nuxt.com/docs/api/nuxt-config#sourcemap)), and the Sentry Nuxt Module keeps these settings when they are explicitly defined.
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
1-
```html {tabTitle:Vue} {filename:ErrorButton.vue}
1+
On the client-side:
2+
3+
```html {tabTitle:Vue} {filename:pages/example-error.vue}
24
<script setup>
3-
const triggerError = () => {
4-
throw new Error("Nuxt Button Error");
5-
};
5+
import * as Sentry from '@sentry/nuxt';
6+
import { useFetch} from '#imports'
7+
8+
function triggerClientError() {
9+
throw new Error("Nuxt Button Error");
10+
};
11+
12+
function getSentryData() {
13+
Sentry.startSpan(
14+
{
15+
name: 'Example Frontend Span',
16+
op: 'test'
17+
},
18+
async () => {
19+
await useFetch('/sentry-example-api');
20+
}
21+
)
22+
}
623
</script>
724

825
<template>
9-
<button id="errorBtn" @click="triggerError">Trigger Error</button>
26+
<button id="errorBtn" @click="triggerClientError">
27+
Throw Client Error
28+
</button>
29+
<button type="button" @click="getSentryData">
30+
Throw Server Error
31+
</button>
1032
</template>
1133
```
1234

35+
On the server-side:
36+
37+
```js {tabTitle:Nitro} {filename:server/sentry-example-api.ts}
38+
import { defineEventHandler } from '#imports';
39+
40+
export default defineEventHandler(event => {
41+
throw new Error("Sentry Example API Route Error");
42+
});
43+
44+
```
45+
46+
<Alert level="warning">
47+
Keep in mind, that the server-side monitoring **does not work in development mode!**
1348

49+
If you want to test server-side monitoring locally, build your project and run:
50+
```
51+
# Start your app after building your project with `nuxi build`
52+
node .output/server/index.mjs
53+
```
1454

55+
In case you experience any issues with the server-side setup, check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
56+
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>.
57+
</Alert>

0 commit comments

Comments
 (0)