Using TypeScript, I's using EventEmitter to listen the events exposed by node:events.
import EventEmitter from 'events';
const eventEmitter = new EventEmitter();
Exception has occurred: TypeError: events_1.default is not a constructor
Here is my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"noEmitOnError": true,
}
}
So, how can I find out the exactly reason?
Add the setting "esModuleInterop": true
in tsconfig.json
file, then everything worked nicely.
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
...
}
}