# Sentry Node.js ESM vs CJS: match the instrument file to the module system

## The pairs

CommonJS:

```
// instrument.js
const Sentry = require("@sentry/node");
Sentry.init({ dsn: "___PUBLIC_DSN___" });
```

```
node --import ./instrument.js app.js
```

ESM (`"type": "module"` in package.json):

```
// instrument.mjs
import * as Sentry from "@sentry/node";

// Ensure to call this before importing any other modules!
Sentry.init({ dsn: "___PUBLIC_DSN___" });
```

```
node --import ./instrument.mjs app.mjs
```

## How this breaks

- ESM app with `instrument.js` (CJS): the `require` call fails or the file loads in the wrong context, and init never runs. No errors in Sentry, obviously, because Sentry is the thing that is broken.
- Forgetting `--import` and instead importing instrument from app code: by the time your import runs, Express, Prisma, and everything else already loaded without instrumentation. You get errors but no traces, and the gap is confusing.
- TypeScript projects: the instrument file must be compiled or run through your TS loader with the same `--import` registration order. `ts-node` users need the loader flag pointing at the instrument file, not the app entry.

## The check

If error events arrive but spans are missing for libraries you expect (http, pg, redis), init ran but too late. Move it earlier via the preload flag. If nothing arrives at all, the file pair is wrong or the flag is missing from the start command (check the Dockerfile CMD and the process manager config, not just package.json scripts).