[英]NestJs websockets UnhandledPromiseRejectionWarning
I'm trying to add a 'events' module to my application for using websockets, but when I add the module I get the following error: 我正在尝试向应用程序中添加一个“事件”模块以使用websockets,但是当我添加该模块时,出现以下错误:
(node:59905) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request mapping properties not defined in the @RequestMapping() annotation!
(node:59905) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
All the other modules are loaded and mapped successfully and it only happens when I add the EventsModule 所有其他模块均已成功加载和映射,并且仅当我添加EventsModule时才会发生
so here's the code that I have: 所以这是我的代码:
app.module.ts app.module.ts
@Module({
modules: [AuthModule, DatabaseModule, UsersModule, TimespansModule, LogsModule, EntitiesModule, EventsModule]
})
events.module.ts events.module.ts
import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
controllers: [EventsComponent]
})
export class EventsModule {}
events.component.ts events.component.ts
import {WebSocketGateway, SubscribeMessage, OnGatewayConnection} from '@nestjs/websockets';
@WebSocketGateway({namespace: 'events'})
export class EventsComponent implements OnGatewayConnection {
handleConnection(client: any) {
console.log('client connected');
}
@SubscribeMessage('stream-received')
onStream(client, data) {
console.log('stream received');
}
}
I can't really see what's going wrong here, also the error message doesn't help me a lot. 我真的看不到这里出了什么问题,错误消息也没有太大帮助。
found the issue in events.module.ts 在events.module.ts中发现了问题
import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
controllers: [EventsComponent]
})
export class EventsModule {}
had to change controllers => components 必须更换控制器=>组件
import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
components: [EventsComponent]
})
export class EventsModule {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.