ยท hands on
Error TS2307: Cannot find module events
If you're extending the `EventEmitter` class from Node.js and encounter the error TS2307 or TS2339, it means you're missing the Node.js type definitions. To fix this, install the typings by running `yarn add @types/node@12 --dev --tilde`. This solution has been tested with TypeScript 3.9.3 and Node.js 12.18.0 LTS.
Extending the EventEmitter
class from Node.js might cause error TS2307. Here is how to fix it.
Contents
Problem
In Node.js you can implement an event listener system using the EventEmitter class:
When executing the code above you may encounter the following errors:
Cannot find module 'events' or its corresponding type declarations.
Property 'emit' does not exist on type ...
Solution
Most of the times these errors are symptoms of missing Node.js type definitions. You can resolve these problems by installing the following typings:
Tested with TypeScript 3.9.3 and Node.js 12.18.0 LTS.