# @metamask/safe-event-emitter

> An EventEmitter that isolates the emitter from errors in handlers

Latest version **3.1.3** (published 2026-08-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @metamask/safe-event-emitter
pnpm add @metamask/safe-event-emitter
yarn add @metamask/safe-event-emitter
bun add @metamask/safe-event-emitter
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.3 |
| Published | 2026-08-26 |
| First published | 2020-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.0.0 |
| Dependencies | 0 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 22 |
| Maintainers | kumavis, frederikbolding, metamaskbot, gudahtt, mrten, mcmire, naugtur |

## Links

- npm: https://www.npmjs.com/package/@metamask/safe-event-emitter
- Repository: https://github.com/MetaMask/safe-event-emitter
- npm.io page: https://npm.io/package/@metamask/safe-event-emitter

## Recent versions

- 3.1.3 (latest) — 2026-08-26
- 3.1.2 — 2024-10-18
- 3.1.1 — 2024-03-12
- 3.1.0 — 2024-03-08
- 3.0.0 — 2023-04-24
- 2.0.0 — 2020-09-22

## README

# safe-event-emitter

An `EventEmitter` that isolates the emitter from errors in handlers. If an error is thrown in a handler it is caught and re-thrown inside of a `setTimeout` so as to not interrupt the emitter's code flow.

The API is the same as a core [`EventEmitter`](https://nodejs.org/api/events.html).

### Install

```bash
$ yarn add '@metamask/safe-event-emitter'
```

### Usage

```js
import SafeEventEmitter from '@metamask/safe-event-emitter';

const ee = new SafeEventEmitter();
ee.on('boom', () => {
  throw new Error();
});
ee.emit('boom'); // No error here

// Error is thrown after setTimeout
```

### Release & Publishing

The project follows the same release process as the other libraries in the MetaMask organization:

1. Create a release branch
   - For a typical release, this would be based on `master`
   - To update an older maintained major version, base the release branch on the major version branch (e.g. `1.x`)
2. Update the changelog
3. Update version in package.json file (e.g. `yarn version --minor --no-git-tag-version`)
4. Create a pull request targeting the base branch (e.g. master or 1.x)
5. Code review and QA
6. Once approved, the PR is squashed & merged
7. The commit on the base branch is tagged
8. The tag can be published as needed

## Running tests

```bash
yarn test
```

---
_Source: https://npm.io/package/@metamask/safe-event-emitter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
