You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nuxt/install/cli-import.mdx
+12-27Lines changed: 12 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,30 @@
1
1
---
2
-
title: --import CLI flag
3
-
sidebar_order: 2
4
-
description: "Learn about using the node `--import` CLI flag."
2
+
title: --import CLI flag (default)
3
+
sidebar_order: 1
4
+
description: "Learn about using the node --import CLI flag."
5
5
---
6
6
7
7
## Understanding the `--import` CLI Flag
8
8
9
-
The [`--import` CLI flag](https://nodejs.org/api/cli.html#--importmodule) in Node allows you to preload modules before the application starts.
9
+
The [`--import` CLI flag](https://nodejs.org/api/cli.html#--importmodule) in Node allows you to preload modules before the application starts. This is the default
10
+
way in ESM to load a module before the application starts.
10
11
If you cannot use the SDK's <PlatformLinkto="/install/dynamic-import/">default dynamic import behaviour</PlatformLink>, setting
11
12
this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
12
13
13
14
## Scenarios where `--import` does not work
14
15
15
16
- You're not able to add Node CLI flags or environment variables that are scoped to the function runtime
16
-
- As of now, Netlify only supports adding scoped environment variables in the paid plan
17
-
- As of now, Vercel does not provide an option for scoping environment variables
17
+
- As of now, **Netlify** only supports adding scoped environment variables in the paid plan
18
+
- As of now, **Vercel** does not provide an option for scoping environment variables
18
19
19
20
If any of those points apply to you, you cannot use the `--import` flag to initialize Sentry on the server-side.
20
-
Check out the guide for using <PlatformLinkto="/install/dynamic-import/">dynamic import</PlatformLink> instead.
21
+
Check out the guide for using <PlatformLinkto="/install/top-level-import/">a top-level import</PlatformLink> or a <PlatformLinkto="/install/dynamic-import/">dynamic import</PlatformLink> instead.
21
22
22
23
## Initializing Sentry with `--import`
23
24
24
-
To successfully use the `--import` flag, follow these steps:
25
+
By default, the SDK will add the Sentry server config to the build output (typically `.output/server/sentry.server.config.mjs`).
25
26
26
-
### 1. Disable Dynamic Import
27
-
28
-
First, disable the dynamic import by setting `dynamicImportForServerEntry` to `false`:
29
-
30
-
```javascript {filename: nuxt.config.ts} {5}
31
-
exportdefaultdefineNuxtConfig({
32
-
modules: ["@sentry/nuxt/module"],
33
-
34
-
sentry: {
35
-
dynamicImportForServerEntry:false,
36
-
},
37
-
});
38
-
```
39
-
40
-
By disabling the dynamic import, the SDK will add the Sentry server config to the build output (typically `.output/server/sentry.server.config.mjs`).
41
-
42
-
### 2. Adding `--import` to `node` command
27
+
### 1. Adding `--import` to `node` command
43
28
44
29
After building your Nuxt app with `nuxi build`, add the `--import` flag followed by the Sentry server config path to the `node` command.
45
30
With the default Nitro Node preset, this typically looks like this:
@@ -57,13 +42,13 @@ To make things easier, add a script in the `package.json`:
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).
32
-
We are working on figuring this out ([see issue here](https://github.com/getsentry/sentry-javascript/issues/14514)). As a temporary workaround, you can add the following overrides to your application:
43
+
Depending on your setup and which version of Nitro is used, the server-side is sometimes not correctly initialized.
44
+
The build output **must not** include a regular `import` of the Nitro runtime (e.g. `import './chunks/nitro/nitro.mjs'`).
45
+
See the ([GitHub issue here](https://github.com/getsentry/sentry-javascript/issues/14514)) for more information.
46
+
47
+
As a temporary workaround, you can add the following overrides to your application:
33
48
34
49
```json {tabTitle:npm} {filename:package.json}
35
50
"overrides": {
@@ -52,7 +67,7 @@ We are working on figuring this out ([see issue here](https://github.com/getsent
52
67
}
53
68
```
54
69
55
-
You can also check out the guide for using the <PlatformLinkto="/install/cli-import//">CLI flag `--import`</PlatformLink> as this might be a better choice for you.
70
+
You can also check out the guide for using the <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or <PlatformLinkto="/install/top-level-import/">a top-level import</PlatformLink> as this might be a better choice for you.
description: "Learn about how the Nuxt SDK adds a top-level import to the build output."
5
+
---
6
+
7
+
## Understanding top-level `import`
8
+
9
+
Sentry needs to be initialized before the application starts.
10
+
If the default way of adding an <PlatformLinkto="/install/cli-import">`--import` CLI flag</PlatformLink> flag does not work for you,
11
+
set up the SDK for adding a top-level `import`. This will import the Sentry server-side config at the top of the server entry file.
12
+
In this scenario, Sentry is not initialized before application startup, but as early as otherwise possible.
13
+
14
+
<Alertlevel='warning'title='Restrictions of this installation method'>
15
+
This installation method has a fundamental restriction: It only supports limited performance instrumentation. Only basic `http` instrumentation will work, and no DB or framework-specific instrumentation will be available.
16
+
17
+
Because of this, we recommend using this only if the `--import` flag is not an option for you.
18
+
</Alert>
19
+
20
+
## Initializing Sentry with a top-level `import`
21
+
22
+
Enable the top-level `import` by setting `autoInjectServerSentry`:
23
+
24
+
```typescript {filename:nuxt.config.ts} {3}
25
+
exportdefaultdefineNuxtConfig({
26
+
sentry: {
27
+
autoInjectServerSentry: 'top-level-import'
28
+
},
29
+
})
30
+
```
31
+
32
+
By default, the SDK will add the Sentry server config to the build output (typically `.output/server/sentry.server.config.mjs`).
33
+
34
+
With the top-level `import`, the server entry file will look something like this:
35
+
36
+
```javascript {filename:.output/server/index.mjs}
37
+
import'./sentry.server.config.mjs';
38
+
// Note: The file may have some imports and code related to debug IDs
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nuxt/manual-setup.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,12 @@ dotenv.config();
125
125
// ... rest of the file
126
126
```
127
127
128
+
#### Load Sentry config
129
+
130
+
Sentry can only be loaded on the server-side if it is explicitly added via `--import`.
131
+
132
+
Refer to the documentation of using <PlatformLinkto="/install/cli-import">`--import` CLI flag</PlatformLink> for setup instructions.
133
+
128
134
<Alertlevel="warning">
129
135
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)
0 commit comments