【问题标题】:NestJs websockets UnhandledPromiseRejectionWarningNestJs websockets UnhandledPromiseRejectionWarning
【发布时间】:2018-05-20 08:54:45
【问题描述】:

我正在尝试将“事件”模块添加到我的应用程序以使用 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');
    }
}

我真的看不出这里出了什么问题,而且错误消息对我没有多大帮助。

【问题讨论】:

    标签: javascript node.js typescript websocket nestjs


    【解决方案1】:

    在 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 {}
    

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 2021-09-26
      • 2021-05-31
      • 2020-06-26
      • 2020-06-08
      • 2020-02-07
      • 2021-06-14
      • 2021-02-18
      • 2020-08-23
      相关资源
      最近更新 更多