---
title: "Installation Methods"
description: "Review our alternate installation methods."
url: https://docs.sentry.io/platforms/javascript/guides/koa/install/
---

# Installation Methods | Sentry for Koa

* #### [With a Bundler](https://docs.sentry.io/platforms/javascript/guides/koa/install/bundler.md)

  Learn how to run your app with Sentry using a bundler plugin, without the --import flag.

* #### [Late Initialization](https://docs.sentry.io/platforms/javascript/guides/koa/install/late-initialization.md)

  Learn about running Sentry in an ESM or CJS application, in scenarios where you cannot run init early.

* #### [Deferred Entrypoint](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md)

  Learn about running Sentry without the --import flag.

* #### [Single Executable Applications](https://docs.sentry.io/platforms/javascript/guides/koa/install/single-executable-applications.md)

  Learn about running Sentry in a Single Executable Application (SEA)

## [How To Decide Which Installation Method To Use](https://docs.sentry.io/platforms/javascript/guides/koa/install.md#how-to-decide-which-installation-method-to-use)

The SDK has to wrap the modules your application uses before your application imports them. How you arrange that is the only difference between the methods below. `--import` works for both ESM and CommonJS applications, so the module system your application uses no longer decides the method.

### [Load Your Instrument File With `--import` (Recommended)](https://docs.sentry.io/platforms/javascript/guides/koa/install.md#load-your-instrument-file-with---import-recommended)

Put `Sentry.init()` in an instrument file and load it with the `--import` flag:

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

This runs `Sentry.init()` before any of your application's modules load, so every instrumented library is wrapped and every error during startup is captured. Use this unless one of the cases below applies to you.

`--import` works for CommonJS applications too, with an `instrument.js` file:

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

Note that `--require` is no longer supported for initialization.

### [Bundler Plugin and a Top-Level Import](https://docs.sentry.io/platforms/javascript/guides/koa/install.md#bundler-plugin-and-a-top-level-import)

If you build your server with a bundler, instrument your dependencies at build time with the Sentry bundler plugin and import `instrument.mjs` at the top of your entry file. Because the plugin bakes the instrumentation into your bundle, a top-level import is enough and you don't need a flag on the Node.js binary. See [With a Bundler](https://docs.sentry.io/platforms/javascript/guides/koa/install/bundler.md).

If you can't use a bundler, a top-level import on its own isn't equivalent to `--import`, because ESM evaluates every import in a file before it runs the first line of that file. See [Deferred Entrypoint](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md) for an alternative way to run your application in this case.

### [Prepare the instrumentation with `--import` and Initialize Later](https://docs.sentry.io/platforms/javascript/guides/koa/install.md#prepare-the-instrumentation-with---import-and-initialize-later)

If you can't call `Sentry.init()` at startup, for example because you fetch your DSN from an external source, `--import` the instrumentation early and call `Sentry.init()` at a later point:

```bash
node --import @sentry/node/import main.mjs
```

See [Late Initialization](https://docs.sentry.io/platforms/javascript/guides/koa/install/late-initialization.md).

## Pages in this section

- [With a Bundler](https://docs.sentry.io/platforms/javascript/guides/koa/install/bundler.md)
- [Late Initialization](https://docs.sentry.io/platforms/javascript/guides/koa/install/late-initialization.md)
- [Deferred Entrypoint](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm-without-import.md)
- [Single Executable Applications](https://docs.sentry.io/platforms/javascript/guides/koa/install/single-executable-applications.md)
- [ESM (MJS)](https://docs.sentry.io/platforms/javascript/guides/koa/install/esm__v8.x.md)
