{"id":15059,"library":"wolfy87-eventemitter","title":"EventEmitter","description":"wolfy87-eventemitter is a JavaScript event emitter library, primarily designed for use in web browsers but also usable in Node.js environments. It aims to replicate the event-driven paradigm found in Node.js, focusing on a lightweight footprint and fast execution. The library underwent a significant API remapping in its fourth major rewrite to improve clarity and extensibility. While npm shows `5.2.9` as the latest version, the project's GitHub repository has had no activity since 2016, with `v4.2.11` being the last officially tagged release. This indicates the project is no longer actively maintained, making `v4.x` the last stable and documented version.","status":"abandoned","version":"5.2.9","language":"javascript","source_language":"en","source_url":"git://github.com/Olical/EventEmitter","tags":["javascript","eventemitter","events","browser","amd","typescript"],"install":[{"cmd":"npm install wolfy87-eventemitter","lang":"bash","label":"npm"},{"cmd":"yarn add wolfy87-eventemitter","lang":"bash","label":"yarn"},{"cmd":"pnpm add wolfy87-eventemitter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import for modern bundlers or Node.js. Older versions and environments typically use CommonJS `require` or global access.","wrong":"const EventEmitter = require('wolfy87-eventemitter');","symbol":"EventEmitter","correct":"import EventEmitter from 'wolfy87-eventemitter';"},{"note":"CommonJS `require` for Node.js (prior to ESM) or older bundlers. The package might expose a global `EventEmitter` in browser environments when included via a script tag.","wrong":"import EventEmitter from 'wolfy87-eventemitter';","symbol":"EventEmitter","correct":"const EventEmitter = require('wolfy87-eventemitter');"},{"note":"TypeScript type import. The library ships its own type definitions.","symbol":"typeof EventEmitter","correct":"import type EventEmitter from 'wolfy87-eventemitter';"}],"quickstart":{"code":"import EventEmitter from 'wolfy87-eventemitter';\n\nconst emitter = new EventEmitter();\n\n// Register a listener for the 'data' event\nemitter.on('data', (payload: string) => {\n  console.log('Received data:', payload);\n});\n\n// Register a 'once' listener for the 'init' event\nemitter.once('init', () => {\n  console.log('Application initialized.');\n});\n\n// Emit the 'init' event\nemitter.emit('init');\n// This will not log again as 'once' listeners are removed after first emission\nemitter.emit('init');\n\n// Emit the 'data' event with a payload\nemitter.emit('data', 'Hello Event World!');\n\n// Remove a specific listener\nconst anotherListener = (num: number) => console.log('Number received:', num);\nemitter.on('number', anotherListener);\nemitter.emit('number', 42);\nemitter.off('number', anotherListener);\nemitter.emit('number', 100); // This will not log\n\n// Remove all listeners for a specific event\nemitter.on('cleanup', () => console.log('Cleaning up 1'));\nemitter.on('cleanup', () => console.log('Cleaning up 2'));\nemitter.emit('cleanup');\nemitter.removeAllListeners('cleanup');\nemitter.emit('cleanup'); // No output\n","lang":"typescript","description":"Demonstrates basic event handling: registering, emitting, one-time listeners, and removing listeners."},"warnings":[{"fix":"Consider migrating to an actively maintained event emitter library such as `eventemitter3` or Node.js's built-in `events` module if in a Node environment.","message":"The project is abandoned. While `npm` lists `5.2.9`, the GitHub repository has seen no activity since 2016, and `v4.2.11` is the last official release tag. No documentation or migration guides exist for v5.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review The Unlicense terms to ensure compliance with your project's legal requirements.","message":"Starting with `v4.2.11`, the project license changed from MIT to The Unlicense. This is a significant shift in licensing terms, moving to public domain dedication.","severity":"breaking","affected_versions":">=4.2.11"},{"fix":"Refer to the v4.x API documentation for the correct method names and usage patterns, specifically `on`, `emit`, `off`, `once`, `hasListeners`, `getListeners`, `removeAllListeners`.","message":"The `EventEmitter` API underwent a significant remapping and redesign in its fourth major rewrite (v4.x). If upgrading from very old versions (pre-4.x), many method names and behaviors will have changed.","severity":"gotcha","affected_versions":"<4.0.0"},{"fix":"Update calls to `removeEvent(eventName)` to `removeAllListeners(eventName)` for improved clarity and Node.js API conformity.","message":"The `removeAllListeners` method was added as an alias to `removeEvent` in `v4.2.4` to align with the Node.js API. While `removeEvent` still functions, `removeAllListeners` is the more consistent and recommended method name.","severity":"gotcha","affected_versions":"<4.2.4"},{"fix":"Ensure you are using `v4.2.3` or higher to mitigate potential infinite recursion issues with `once` listeners.","message":"An infinite recursion bug was present in `addOnceListener` in versions prior to `v4.2.3` under specific conditions.","severity":"gotcha","affected_versions":"<4.2.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using the correct import/require syntax for your environment. For modern ESM environments: `import EventEmitter from 'wolfy87-eventemitter';`. For CommonJS: `const EventEmitter = require('wolfy87-eventemitter');`. In browsers (script tag), it might be globally available as `window.EventEmitter`.","cause":"Attempting to instantiate `EventEmitter` without correctly importing or accessing it, often due to CommonJS/ESM module mismatches or incorrect global access in the browser.","error":"TypeError: EventEmitter is not a constructor"},{"fix":"Verify that your `EventEmitter` instance (`emitter` in examples) is properly initialized with `new EventEmitter()` before attempting to use its methods.","cause":"Attempting to call methods like `on` or `emit` on an `EventEmitter` instance that is undefined or null, usually due to incorrect initialization or scope issues.","error":"TypeError: Cannot read properties of undefined (reading 'on')"},{"fix":"Upgrade to `v4.2.7` or later, which includes a fix for this specific Android 2.2 browser bug. Note that this is for a very old browser version.","cause":"A bug in older Android 2.2 browsers related to `RegExp` type checking prevented proper functionality.","error":"Uncaught TypeError: Android 2.2 RegExp type check issue"}],"ecosystem":"npm"}