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
You need to import the `instrument.mjs` file before importing any other modules in your application. This is necessary to ensure that Sentry can automatically instrument all modules in your application:
41
+
**Step 2:** Import the `instrument.mjs` file before importing any other modules in your in the `main.ts` file of your application. This ensures that Sentry can automatically instrument all modules in your application:
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nestjs/install/esm.mdx
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@ supported:
11
11
[installation methods](../).
12
12
</Alert>
13
13
14
-
When running your application in ESM mode, you can't use `require()` to load modules. Instead, you have to use the `--import` command line options to load a module before the application starts.
14
+
When running your application in [ECMAScript Modules](https://nodejs.org/api/esm.html#introduction) (ESM) mode, you can't use `require()` to load modules. Instead, you have to use the `--import` command line options to load a module before the application starts.
15
15
16
-
You need to create a file named `instrument.mjs` that imports and initializes Sentry:
16
+
**Step 1:** Create a file named `instrument.mjs` that imports and initializes Sentry:
Adjust the Node.js call for your applicationto use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter and point it at `instrument.mjs`, which contains your `Sentry.init()` code:
31
+
**Step 2:** Adjust your application's start command to use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter:
32
32
33
33
```bash
34
34
# Note: This is only available for Node v18.19.0 onwards.
35
-
node --import ./instrument.mjs dist/main.js
35
+
"start": "--import ./instrument.mjs nest start"
36
36
```
37
37
38
-
If it is not possible for you to pass the `--import` flag to the Node.js binary, you can alternatively use the `NODE_OPTIONS` environment variable as follows:
38
+
If you can't pass the `--import` flag to the Node.js binary, you can alternatively use the `NODE_OPTIONS` environment variable as follows:
39
39
40
40
```bash
41
41
NODE_OPTIONS="--import ./instrument.mjs" npm run start
42
42
```
43
43
44
-
We do not support ESM in Node versions before 18.19.0.
44
+
<Alert>We do not support ESM in Node versions before 18.19.0.</Alert>
45
45
46
-
## Troubleshooting instrumentation
46
+
## Troubleshooting ESM Instrumentation
47
47
48
-
By default, all packages are wrapped under the hood by
48
+
By default, all packages are automatically wrapped by
49
49
[import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle) to
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nestjs/install/esm__v8.x.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ noindex: true
12
12
[installation methods](../).
13
13
</Alert>
14
14
15
-
When running your application in ESM mode, you can't use `require()` to load modules. Instead, you have to use the `--import` command line options to load a module before the application starts.
15
+
When running your application in [ECMAScript Modules](https://nodejs.org/api/esm.html#introduction) (ESM) mode, you can't use `require()` to load modules. Instead, you have to use the `--import` command line options to load a module before the application starts.
16
16
17
-
You need to create a file named `instrument.mjs` that imports and initializes Sentry:
17
+
**Step 1:** Create a file named `instrument.mjs` that imports and initializes Sentry:
Adjust the Node.js call for your applicationto use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter and point it at `instrument.js`, which contains your `Sentry.init()` code:
32
+
**Step 2:** Adjust your application's start command to use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter:
33
33
34
34
```bash
35
35
# Note: This is only available for Node v18.19.0 onwards.
36
-
node --import ./instrument.mjs dist/main.js
36
+
"start": "--import ./instrument.mjs nest start"
37
37
```
38
38
39
-
If it is not possible for you to pass the `--import` flag to the Node.js binary, you can alternatively use the `NODE_OPTIONS` environment variable as follows:
39
+
If you can't pass the `--import` flag to the Node.js binary, you can alternatively use the `NODE_OPTIONS` environment variable as follows:
40
40
41
41
```bash
42
42
NODE_OPTIONS="--import ./instrument.mjs" npm run start
43
43
```
44
44
45
-
We do not support ESM in Node versions before 18.19.0.
45
+
<Alert>We do not support ESM in Node versions before 18.19.0.</Alert>
46
46
47
47
## Troubleshooting instrumentation
48
48
49
-
By default, all packages are wrapped under the hood by
49
+
By default, all packages are automatically wrapped by
50
50
[import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle) to
description: "Review our alternate installation methods for Sentry using Nest.js."
5
5
supported:
6
6
- javascript.nestjs
7
7
---
@@ -11,24 +11,20 @@ supported:
11
11
## How To Decide Which Installation Method To Use
12
12
13
13
Most node applications today are either written in CommonJS (CJS), or compiled to CJS before running them.
14
-
CommonJS uses `require()` to load modules. Our recommended installation method when using CommonJS is to require the `instrument.js` file at the top of your application. However, if your application is run in ESM mode, this will not work. In this case, you can follow the [ESM docs](./esm).
14
+
CommonJS uses `require()` to load modules. Our recommended installation method when using CommonJS is to require the `instrument.js` file at the top of your application. However, if your application is run in ESM mode, this will not work, in which case, you can follow the [ESM docs](./esm).
15
15
16
16
Note that even if your application is written in ESM (using `import`), it may still be _run_ in CJS. In this case, you should follow the [CommonJS instructions](./commonjs).
17
17
18
18
### My application uses the default Nest.js setup
19
19
20
20
Nest.js transpiles to CJS by default, so you should follow the [CommonJS installation instructions](./commonjs). Keep reading if you have a more customized application or build setup.
21
21
22
-
### My application is in TypeScript
23
-
24
-
If you're using TypeScript, your application is likely compiled to CommonJS before running it. In this case, you should follow the [CommonJS instructions](./commonjs).
25
-
26
22
### My application uses `require`
27
23
28
-
If you are using `require()` in your application, you should follow the [CommonJS instructions](./commonjs).
24
+
If you're using `require()` in your application, you should follow the [CommonJS instructions](./commonjs).
29
25
30
26
### My application uses `import`
31
27
32
-
If you are using `import` in your application, your installation method depends on how your application is _run_. If you compile your application (e.g. into a `/dist` folder or similar) before running this, you need to check how the compiled code looks like. Is the compiled code using `require`? Then you should follow the [CommonJS instructions](./commonjs). If the compiled code is using `import`, you should follow the [ESM instructions](./esm).
28
+
If you're using `import` in your application, your installation method depends on how your application is _run_. If you compile your application (for example, into a `/dist` folder or similar) before running it, you need to check how the compiled code looks like. Is the compiled code using `require`? Then you should follow the [CommonJS instructions](./commonjs). If the compiled code is using `import`, you should follow the [ESM instructions](./esm).
33
29
34
30
If you do not compile your code, you'll need to follow the [ESM instructions](./esm).
0 commit comments