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

# Installation Methods for Effect

## [How To Decide Which Installation Method To Use](https://docs.sentry.io/platforms/javascript/guides/effect/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/effect/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/effect/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/effect/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/effect/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/effect/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/effect/install/late-initialization.md).

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

Depending on the concrete needs of your application, you may wonder which installation method you should use.

### [Why Choose the Loader Script Over NPM](https://docs.sentry.io/platforms/javascript/guides/effect/install.md#why-choose-the-loader-script-over-npm)

Using the Loader Script is the easiest way to start using Sentry. Add a script tag to your application, and we'll take care of setting everything else up correctly for you.

* **Easy to set up**: Just [add a script tag](https://docs.sentry.io/platforms/javascript/guides/effect/install/loader.md#using-the-loader) to your application.

* **Easy to upgrade**: We'll take care of always shipping the latest version of the SDK to your users. No action's needed from you. This ensures you'll always get the latest features and bug fixes of the Sentry SDK.

* **Easy to add additional configuration**: You can [configure the SDK](https://docs.sentry.io/platforms/javascript/guides/effect/install/loader.md#sdk-configuration) to your liking via `window.sentryOnLoad`.

* **Lazy-loading**: If you just want to use Sentry for errors, we'll only load the SDK when an error occurs, reducing the amount of JavaScript loaded on your page until then.

  Note that when enabling Session Replay and/or Tracing, the SDK will be loaded immediately because we need to capture what's happening on the page as early as possible.

### [Why Choose NPM Over the Loader Script](https://docs.sentry.io/platforms/javascript/guides/effect/install.md#why-choose-npm-over-the-loader-script)

While using the Loader Script has definite advantages, it also comes with some drawbacks. In these scenarios, using the npm package is the better choice:

* **Framework-specific initialization**: As of now, the Loader Script only provides generic Browser JavaScript instrumentation. This means that you won't get any React, Vue, or similar framework-specific features for Sentry. To get these features, you'll need to install the framework SDK (e.g. `@sentry/react` or `@sentry/vue`) via npm.

* **Full public API**: The Loader Script only exposes a subset of public APIs (for example, `Sentry.captureException()`, ...). If you need a lot of custom functionality, you're likely better off with the npm package.

* **Full control over the SDK version**: If you need full control over the SDK version, you'll need to install the SDK via npm.
