Skip to content

docs(nuxt): Add readme docs for server-side setup (ESM) #13019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions packages/nuxt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ Sentry.init({

### 4. Server-side setup

Add a `sentry.server.config.(js|ts)` file to the root of your project:

```javascript
import * as Sentry from '@sentry/nuxt';

Sentry.init({
dsn: process.env.DSN,
});
```

**Alternative Setup (ESM-compatible)**

This setup makes sure Sentry is imported on the server before any other imports. As of now, this however leads to an
import-in-the-middle error ([related reproduction](https://github.com/getsentry/sentry-javascript-examples/pull/38)).

Add an `instrument.server.mjs` file to your `public` folder:

```javascript
Expand All @@ -130,7 +115,8 @@ if (process.env.SENTRY_DSN) {
}
```

Add an import flag to the node options, so the file loads before any other imports:
Add an import flag to the `NODE_OPTIONS` of your preview script in the `package.json` file, so the file loads before any
other imports:

```json
{
Expand All @@ -140,6 +126,18 @@ Add an import flag to the node options, so the file loads before any other impor
}
```

If you are getting an `import-in-the-middle` error message, add the package with a minimum version of `1.10.0` as a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: I'm curious - Is there a concrete reason in Nuxt apps why users would run into this error? I think this is already rather specific for the SDK readme as it sounds a bit more like troubleshooting.

Generally, I'd tend towards keeping the Readmes in the repo rather short in favour of more detailed docs. They almost inevitably diverge at some point 🥲 But given we don't have docs yet for nuxt we can also leave this in and rethink if we need it once we give the readme a pass before going stable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem will most likely occur because of iitm-related issues with vue/server-renderer (repro here and other issue comment here). That's why I added it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can look at this in a follow up, but maybe we can auto-add this package to the exclude config for the users 🤔

dependency to your `package.json`
([issue reference](https://github.com/getsentry/sentry-javascript-examples/pull/38#issuecomment-2245259327)):

```json
{
"dependencies": {
"import-in-the-middle": "1.10.0"
}
}
```

### 5. Vite Setup

todo: add vite setup
Expand Down
Loading