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
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,18 +6,19 @@ description: "Learn how to use the node --import CLI flag."
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 is the default way in ESM to preload a module before the application starts.
10
-
If you cannot use the SDK's <PlatformLinkto="/install/dynamic-import/">default dynamic import behaviour</PlatformLink>, setting
11
-
this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
9
+
The [`--import` CLI flag](https://nodejs.org/api/cli.html#--importmodule) in Node is the default way in ESM to preload a specified module at startup.
10
+
Setting this CLI flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the application runs.
11
+
This will register Sentry's [loader hook](https://nodejs.org/api/module.html#customization-hooks) and therefore enable proper instrumentation of ESM modules.
12
12
13
13
## Scenarios where `--import` does not work
14
14
15
-
- You're not able to add Node CLI flags or environment variables that are scoped to the function runtime
16
-
-**Netlify** only allows scoped environment variables on its paid plans at this time
17
-
-**Vercel** doesn't currently provide an option for scoping environment variables
15
+
- You're unable to add Node CLI flags or environment variables scoped to the function runtime, meaning these variables aren't applied in other scopes, such as build time.
16
+
- You don't know the path to the Nuxt server folder in the build output
17
+
- At this time, it isn't possible to properly configure `--import` in **Netlify**.
18
+
- At this time, it isn't possible to properly configure `--import` in **Vercel**.
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/top-level-import/">a top-level import</PlatformLink> or a <PlatformLinkto="/install/dynamic-import/">dynamic import</PlatformLink> instead.
21
+
Check out the guide for using <PlatformLinkto="/install/limited-server-tracing">limited server tracing</PlatformLink> instead.
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nuxt/install/dynamic-import.mdx
+36-29Lines changed: 36 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,37 +6,18 @@ description: "Learn about how the Nuxt SDK leverages dynamic input() in the buil
6
6
7
7
## Understanding the `import()` expression
8
8
9
-
The `import()` expression (also called "dynamic import") allows conditional and flexible module loading in ESM.
10
-
For the Sentry Nuxt SDK, it provides an approach to initialize server-side configuration before application startup.
9
+
<Alertlevel='warning'>
10
+
This installation method doesn't work with more recent versions of Nuxt/Nitro.
11
11
12
-
The Sentry Nuxt SDK will be initialized before any other code runs and the Nitro server runtime code will be loaded later because of `import()`ing it.
13
-
This early initialization is required to set up the SDK's instrumentation of various libraries correctly.
12
+
We recommend reading the guide for installing the SDK with the <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or <PlatformLinkto="/install/limited-server-tracing">limited server tracing</PlatformLink>
13
+
</Alert>
14
14
15
-
## Initializing Sentry with Dynamic `import()`
16
-
17
-
Enable the dynamic `import()` by setting `autoInjectServerSentry`:
The `import()` expression, or dynamic import, enables flexible, conditional module loading in ESM.
16
+
Node.js will generate a separate module graph for any code wrapped in a dynamic `import()`. This separate graph is evaluated **after** all modules, which are statically `import`ed.
26
17
27
-
After setting this, the Sentry Nuxt SDK adds some build-time configuration to ensure your app is wrapped with `import()`.
28
-
With this, Sentry can be initialized before all other modules of the application.
29
-
30
-
The Nuxt server entry file will look something like this:
31
-
32
-
```javascript {filename:.output/server/index.mjs}
33
-
// Note: The file may have some imports and code, related to debug IDs
By using the Sentry Nuxt SDK, the server-side application will be wrapped in a dynamic `import()`, while the Sentry configuration will be imported with a static `import`.
19
+
This makes it possible to initialize the Sentry Nuxt SDK at startup, while the Nitro server runtime loads later because it is `import()`ed.
20
+
This early initialization of Sentry is required to correctly set up the SDK's instrumentation of various libraries.
40
21
41
22
## Scenarios where `import()` doesn't work
42
23
@@ -67,7 +48,33 @@ As a temporary workaround, you can add the following overrides in your applicati
67
48
}
68
49
```
69
50
70
-
You can also check out the guide for installing the SDK with a <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLinkto="/install/top-level-import/">top-level import</PlatformLink>.
51
+
You can also check out the guide for installing the SDK with the <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or <PlatformLinkto="/install/limited-server-tracing">limited-server-tracing</PlatformLink>.
52
+
53
+
## Initializing Sentry with Dynamic `import()`
54
+
55
+
Enable the dynamic `import()` by setting `autoInjectServerSentry`:
0 commit comments