> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# @appsignal/stimulus

## Installation

### With npm or yarn

Add the `@appsignal/stimulus` and `@appsignal/javascript` packages to your `package.json`. Then, run `yarn install`/`npm install`.

You can also add these packages to your `package.json` on the command line:

<CodeGroup>
  ```bash Bash theme={null}
  yarn add @appsignal/javascript @appsignal/stimulus
  npm install @appsignal/javascript @appsignal/stimulus
  ```
</CodeGroup>

### With JSPM.io import maps

Using the [JSPM.io import map generator](https://generator.jspm.io/), you can generate an import map for your application's dependencies.

Add `@appsignal/javascript` and `@appsignal/stimulus` to the dependencies list in the generator, then add the generated import map and ES module shims to your application's code.

### With `rails-importmap`

Use the following command to add these packages to your Rails application's import maps:

<CodeGroup>
  ```sh Shell theme={null}
  ./bin/importmap pin @appsignal/javascript @appsignal/stimulus
  ```
</CodeGroup>

## Usage

### `Application.handleError`

The default Stimulus integration is a function that binds to the `Application.handleError` property. In a new app created using `rails new $APP_NAME --webpack=stimulus`, for example, your `javascript/controllers/index.js` file would look something like this:

<CodeGroup>
  ```js JavaScript theme={null}
  import { Application } from "stimulus";
  import { definitionsFromContext } from "stimulus/webpack-helpers";

  import { appsignal } from "./appsignal";
  import { installErrorHandler } from "@appsignal/stimulus";

  const application = Application.start();
  installErrorHandler(appsignal, application);
  const context = require.context("controllers", true, /_controller\.js$/);
  application.load(definitionsFromContext(context));
  ```
</CodeGroup>
