总是抛出异常“发生异常:TypeError:xxxx.default不是构造函数”

问题描述 投票:0回答:1

使用 TypeScript,我使用 EventEmitter 来监听 node:events 公开的事件。

import EventEmitter from 'events';
const eventEmitter = new EventEmitter();
  • 使用 TypeScript 应用程序(不使用 NestJS)。没有任何例外
  • 但是当我切换到使用 Nestjs 时,它总是抛出预期的异常
    Exception has occurred: TypeError: events_1.default is not a constructor 

这是我的

tsconfig.json

enter image description here

那么,如何才能找到具体原因呢?有经验的请给我正确的答案吗?

提前谢谢您

typescript nestjs
1个回答
0
投票

"esModuleInterop": true
文件中添加设置
tsconfig.json
,然后一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.