我试图添加一个'事件'模块到我的应用程序使用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.
所有其他模块都已成功加载和映射,只有在我添加EventsModule
时才会发生所以这里是我的代码:
app.module.ts
@Module({
modules: [AuthModule, DatabaseModule, UsersModule, TimespansModule, LogsModule, EntitiesModule, EventsModule]
})
events.module.ts
import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
controllers: [EventsComponent]
})
export class EventsModule {}
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');
}
}
我无法真正看到此处出现的问题,错误信息对我的帮助也不大。
答案 0 :(得分:0)
在events.module.ts
中发现了这个问题import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
controllers: [EventsComponent]
})
export class EventsModule {}
必须更改控制器=>部件
import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
components: [EventsComponent]
})
export class EventsModule {}