'typeof EventEmitter' is not a constructor function type
https://github.com/muxinc/mux-node-sdk/blob/f2b3af6065920ace1318a269b3f6fbff46f2ba4f/src/base.ts#L4
By switching my node_modules manually to to
import { EventEmitter } from 'events';
it fixes the problem
@hermano360 Can you please help us understand how you're encountering that particular error, so that we can make sure we get it fixed properly, and if possible also add to our test suite to make sure the issue doesn't repeat?
Hi @jaredsmith! Thanks for responding.
So I am troubleshooting on my end in case it's something that I am doing wrong or to narrow down exactly any configuration setting that may be causing a problem.
Trying to narrow down where I see the problem, I see that it occurs when I am trying to compile using typescript in my npm project using the npx tsc command.
When I run npx tsc -v I see that I am running 4.2.4
My tsconfig.json settings are:
{
"compilerOptions": {
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true,
"target": "esnext"
},
"include": ["src"]
}
Upon running npx tsc I see that I get the following error:
node_modules/@mux/mux-node/dist/base.d.ts:17:35 - error TS2507: Type 'typeof EventEmitter' is not a constructor function type.
17 export declare class Base extends EventEmitter {
~~~~~~~~~~~~
Found 1 error.
error Command failed with exit code 2.
I had been previously on @mux/mux-node version 3.3.1, before trying to upgrade to @mux/mux-node version 6.2.0 in order to use the new slate features. My next troubleshooting steps are just trying to make smaller steps in upgrading to make sure there are smaller upgrading changes.
Is there any other information I can provide to you to give you more context?
I took a look, and it seems like the code is correct. In a dummy app I built, I can reproduce this type error. It also yelled at me about Buffer not being known and recommended that I install @types/node. When I installed it, all the type errors went away.
import { EventEmitter } from 'events';
is probably more correct than the old statement, but it won't solve the root issue.
Without any types installed, in addition to the EventEmitter error, I also get the following error:
node_modules/@mux/mux-node/dist/base.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.
1 /// <reference types="node" />
~~~~
Which again points to needing the node types.
Looking into the TS Handbook, it does seem like it recommends depending on types that you depend on (from https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#dependencies).
I think this module probably needs to move @types/node from devDeps to deps. And in the meantime, anyone who is stuck on this, should install @types/node themselves locally.
This is no longer an issue in Version 8, where we don't use the EventEmitter pattern, please try migrating:
https://github.com/muxinc/mux-node-sdk/releases/tag/v8.0.0