Skip to content

Commit

Permalink
docs(nuxt): Add readme docs for server-side setup (ESM) (#13019)
Browse files Browse the repository at this point in the history
Specify how Nuxt is set up on the server-side. Nuxt v3+ runs with ESM.

---------

Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com>
  • Loading branch information
s1gr1d and andreiborza authored Jul 24, 2024
1 parent 4bdd979 commit aaaedbc
Showing 1 changed file with 14 additions and 16 deletions.
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
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

0 comments on commit aaaedbc

Please sign in to comment.