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
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,17 @@ description: "Learn how to use the node --import CLI flag."
7
7
## Understanding the `--import` CLI Flag
8
8
9
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.
10
+
Setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
12
11
13
12
## Scenarios where `--import` does not work
14
13
15
-
- You're not able to add Node CLI flags or environment variables that are scoped to the function runtime
14
+
- You're not able to add Node CLI flags or environment variables scoped to the function runtime, meaning these variables are not applied in other scopes, such as build time.
15
+
- You don't know the path to the Nuxt server folder in the build output
16
16
-**Netlify** only allows scoped environment variables on its paid plans at this time
17
17
-**Vercel** doesn't currently provide an option for scoping environment variables
18
18
19
19
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.
20
+
Check out the guide for using <PlatformLinkto="/install/top-level-import/">a top-level import</PlatformLink> instead.
We recommend the guide for installing the SDK with the <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLinkto="/install/top-level-import/">top-level import</PlatformLink>
13
+
</Alert>
26
14
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
34
-
Sentry.init({
35
-
dsn:"..."
36
-
});
15
+
The `import()` expression, or dynamic import, enables flexible, conditional module loading in ESM.
16
+
For the Sentry Nuxt SDK, it provides an approach to initialize server-side Sentry configuration before application startup.
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.
19
+
This early initialization is required to set up the SDK's instrumentation of various libraries correctly.
40
20
41
21
## Scenarios where `import()` doesn't work
42
22
@@ -67,7 +47,34 @@ As a temporary workaround, you can add the following overrides in your applicati
67
47
}
68
48
```
69
49
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>.
50
+
You can also check out the guide for installing the SDK with the <PlatformLinkto="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLinkto="/install/top-level-import/">top-level import</PlatformLink>.
51
+
52
+
53
+
## Initializing Sentry with Dynamic `import()`
54
+
55
+
Enable the dynamic `import()` by setting `autoInjectServerSentry`:
0 commit comments