---
title: "ESM without CLI Flag"
description: "Learn about running Sentry in an ESM application, without the --import flag."
url: https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import/
---

# ESM without CLI Flag | Sentry for Koa

Are you unsure if you should use this installation method? Review our [installation methods](https://docs.sentry.io/platforms/javascript/guides/koa/install.md).

When running your application in ESM mode, you will most likely want to [follow the ESM instructions](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm.md). However, if you can't use the `--import` command line option, you can either use [direct imports](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md#direct-imports) or [SEA bootstrap setup](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md#nodejs-single-executable-applications) if you are using a Node.js Single Executable Application (SEA).

## [Direct Imports](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md#direct-imports)

##### Restrictions of this installation method

This installation method has the fundamental restriction that only native Node.js APIs can be instrumented (such as `fetch` and the `http` module).

As a result, the Sentry SDK will not capture data from database calls, queues, ORMs, third-party libraries, or other framework-specific data.

We recommend using this only if the `--import` flag is not an option for you.

You need to create a file named `instrument.mjs` that imports and initializes Sentry:

**\[ESM] instrument.mjs**

```javascript
import * as Sentry from "@sentry/node";

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

  // Add Tracing by setting tracesSampleRate
  // We recommend adjusting this value in production
  tracesSampleRate: 1.0,
});
```

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:

**\[javascript] app.mjs**

```javascript
// Import this first!
import "./instrument";

// Now import other modules
import http from "http";

// Your application code goes here
```

## [Node.js Single Executable Applications](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md#nodejs-single-executable-applications)

Node.js Single Executable Applications (SEA) may not load your Sentry instrumentation early enough, so you need to package a small bootstrap file as the SEA main instead of packaging your app entrypoint directly.

The embedded SEA main should only load a filesystem bootstrap file next to the executable:

**\[javascript] sea-main.cjs**

```javascript
const { createRequire } = require("node:module");

createRequire(__filename)("./sea-bootstrap.cjs");
```

The filesystem bootstrap imports Sentry first, then imports your real app entrypoint:

**\[javascript] sea-bootstrap.cjs**

```javascript
async function startApp() {
  await import("./instrument.mjs");
  await import("./app.mjs");
}

startApp();
```

Keep your Sentry setup in `instrument.mjs`:

**\[ESM] instrument.mjs**

```javascript
import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
});
```

Then configure SEA to use `sea-main.cjs` as its main script:

**\[json] sea-config.json**

```json
{
  "main": "sea-main.cjs",
  "output": "sea-prep.blob",
  "disableExperimentalSEAWarning": true,
  "useSnapshot": false
}
```

Keep `sea-bootstrap.cjs`, `instrument.mjs`, and `app.mjs` available on the filesystem next to the executable.

This setup lets the Sentry SDK register ESM instrumentation hooks before your application imports instrumented modules, such as Express or database clients. Your instrumentation file and app entrypoint can stay ESM. The verified bootstrap pattern shown here uses CommonJS only for the small SEA entry files.

Node.js SEA support is still evolving, including how embedded ESM entrypoints and module loading are configured. The embedded SEA main may not be able to load filesystem modules with `import()` directly, so the example above uses `module.createRequire()` to bridge from the embedded main to a normal filesystem bootstrap. The important requirement is startup order: load Sentry before loading the application modules you want Sentry to instrument.
