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/common/install/esm-without-import.mdx
+5-3Lines changed: 5 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,12 @@ supported:
20
20
When running your application in ESM mode, you will most likely want to <PlatformLinkto="/install/esm">follow the ESM instructions</PlatformLink>. However, if you want to avoid using the `--import` command line option, for example if you have no way of configuring a CLI flag, you can also follow an alternative setup that involves importing the `instrument.mjs` file directly in your application.
21
21
22
22
<Alertlevel='warning'title='Restrictions of this installation method'>
23
-
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.
24
-
25
-
Because of this, we recommend using this only if the `--import` flag is not an option for you.
23
+
This installation method has fundamental restrictions:
24
+
- It only supports limited performance instrumentation.
25
+
- Only basic `http` instrumentation will work.
26
+
- No DB or framework-specific instrumentation will be available.
26
27
28
+
We recommend using this only if the `--import` flag is not an option for you.
27
29
</Alert>
28
30
29
31
You need to create a file named `instrument.mjs` that imports and initializes Sentry:
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nuxt/install/cli-import.mdx
+10-27Lines changed: 10 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,29 @@
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 how to use 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 is the default way in ESM to preload a module before the application starts.
10
10
If you cannot use the SDK's <PlatformLinkto="/install/dynamic-import/">default dynamic import behaviour</PlatformLink>, setting
11
11
this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
12
12
13
13
## Scenarios where `--import` does not work
14
14
15
15
- 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
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
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/dynamic-import/">dynamic import</PlatformLink> instead.
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
21
22
22
## Initializing Sentry with `--import`
23
23
24
-
To successfully use the `--import` flag, follow these steps:
24
+
By default, the SDK will add the Sentry server config to the build output (typically, `.output/server/sentry.server.config.mjs`).
25
25
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
26
+
### 1. Adding `--import` to `node` command
43
27
44
28
After building your Nuxt app with `nuxi build`, add the `--import` flag followed by the Sentry server config path to the `node` command.
45
29
With the default Nitro Node preset, this typically looks like this:
@@ -57,13 +41,12 @@ 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 in your application:
33
48
34
49
```json {tabTitle:npm} {filename:package.json}
35
50
"overrides": {
@@ -52,16 +67,14 @@ 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.
56
-
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>.
57
71
58
72
## Re-exporting serverless handler functions
59
73
60
74
Sentry automatically detects serverless handler functions in the build output and re-exports them from the server entry file.
61
75
62
76
By default, Sentry re-exports functions named `handler`, `server`, and `default` exports. This will work in most cases and no other action is required.
63
-
In case your serverless function has another, custom name you can override this with `entrypointWrappedFunctions`:
64
-
77
+
If your serverless function has a custom name, you can override it with `experimental_entrypointWrappedFunctions`:
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nuxt/manual-setup.mdx
+6Lines changed: 6 additions & 0 deletions
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 by being explicitly added via `--import`.
131
+
132
+
Check out the <PlatformLinkto="/install/cli-import">`--import` CLI flag</PlatformLink> docs 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